|
-
Feb 22nd, 2000, 09:45 PM
#1
Thread Starter
New Member
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.
-
Feb 22nd, 2000, 09:54 PM
#2
Fanatic Member
Try this:
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
And then you call it with:
Code:
'Set Label1.Text equal to Random String
Label1.Text = RandomString()
r0ach™
Don't forget to rate the post
-
Feb 22nd, 2000, 10:40 PM
#3
Thread Starter
New Member
weell.. when does the function randomize the strings? if my string name is frstr1 and frstr2 etc. when where shall i put their names?
-
Feb 22nd, 2000, 10:40 PM
#4
Thread Starter
New Member
weell.. when does the function randomize the strings? if my string name is frstr1 and frstr2 etc. when where shall i put their names?
-
Feb 22nd, 2000, 11:19 PM
#5
Fanatic Member
Replace the For loop in the RandomString Function with:
Code:
strArray(0) = frstr1
strArray(1) = frstr2
strArray(2) = frstr3
strArray(3) = frstr4
strArray(4) = frstr5
strArray(5) = frstr6
strArray(6) = frstr7
This is how it works:
You generate a random integer (like you already know how to ) and then use it as an Index for an array holding your strings
r0ach™
Don't forget to rate the post
-
Feb 22nd, 2000, 11:37 PM
#6
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.
-
Feb 23rd, 2000, 12:24 AM
#7
Fanatic Member
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.
r0ach™
Don't forget to rate the post
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|