shg, I stumbled on this thread yesterday and the concept intrigues me, as I am just now beginning to work with defining "custom" functions...
I just wanted to ask before I screw up my code in my project, does this portion of code:
Function RandTitle() As String
Static avsTitle As Variant
If IsEmpty(avsTitle) Then avsTitle = Split("Darn,Drat,EGAD!,Holy Cow!,Shoot!,Not so fast!,Oops!,Slow down!,That won't work", ",")
RandTitle = avsTitle(Int(Rnd() * (UBound(avsTitle) + 1)))
End Function
need to be placed in its' own section of the full code like a sub, or does it go inside the sub you want to use it in? I'm assuming it is separate, and only needs to be inserted once, is that correct?
Also, if I wanted to use this "trick" on more than one message box with a different list of random titles for each, would I just duplicate the code with different variable names, like so?
Function SecondRandTitle() As String
Static avsTitle2 As Variant
If IsEmpty(avsTitle2) Then avsTitle2 = Split("Nope,Nice Try,Close but no cigar,Better luck next time", ",")
SecondRandTitle = avsTitle2(Int(Rnd() * (UBound(avsTitle2) + 1)))
End Function
And finally, is it possible with the above code to use a comma within one of the random title options, for instance if you wanted to use "I don't think so, Scooter!" as one of the options? If so, how would you handle that?
(Mods - Sorry if this should be a separate thread, it seemed like it would be better to continue the discussion here for relevancy... If I was wrong, let me know please.)
Bookmarks