I have to randomize 7 strings in my application. And I do know how to randomize *******s but not how to randomize strings. I also wounder how to check that the string don't come twice. Please help me this.
Printable View
I have to randomize 7 strings in my application. And I do know how to randomize *******s but not how to randomize strings. I also wounder how to check that the string don't come twice. Please help me this.
Try this:
And then you call it with:Code:Public Function RandomString() as String
ReDim strArray(0 to 6) as string
Dim i as integer
' Fill String Array
For i = 0 to 6
strArray(i) = "String number " & (i + 1)
Next
Randomize Timer
' Get Random Array Index
i = Int(Rnd * 7)
' Set Function equal to random string
RandomString = strArray(i)
End Function
Code:'Set Label1.Text equal to Random String
Label1.Text = RandomString()
weell.. when does the function randomize the strings? if my string name is frstr1 and frstr2 etc. when where shall i put their names?
weell.. when does the function randomize the strings? if my string name is frstr1 and frstr2 etc. when where shall i put their names?
Replace the For loop in the RandomString Function with:
This is how it works:Code:strArray(0) = frstr1
strArray(1) = frstr2
strArray(2) = frstr3
strArray(3) = frstr4
strArray(4) = frstr5
strArray(5) = frstr6
strArray(6) = frstr7
You generate a random integer (like you already know how to :) ) and then use it as an Index for an array holding your strings
Do you currently have your strings in an array?
Are they generated strings and there is only seven or is there a lot more strings and you only want to choose seven of them?
Roach is right about indexing, but you need your strings to be in an array.
If you create a duplicate array defined as boolean, when you use the string you can set the indexed boolean to true and then when you generate your random index check the boolean value for true and if it is generate a different index. Or you could loop through the previously retrieved strings and see if they match.
If you are looking for a code solution, I need more information.
Uhmmm. It would be even better if you assign the Strings to the array in the Form_Load() and not in the RandomString() like i did. :o