You have to save them yourself
Obviously if you do not want the same sequence every time you run your program, and if you do not want to get a new sequence every time you open your form2, you will have to save the random sequence of strings the first time you enter form2.
The only alternative is to seed VB's Randomiser yourself and reuse the same value each subsequent time.
This will allow you to keep the same sequence of numbers without storing them in memory (only storing the seed number). This will keep the same sequence until the next time you restart the application. If this is what you want, then use something like the following code.
Code:
' form1 has a single command button
Option Explicit
Private Sub Command1_Click()
Form2.Show
End Sub
Code:
' form2 has a single command button and a list box
Option Explicit
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Static seed As Double
' note that we use the timer for a seed value which is
' the same as VB does if Randomize is called with
' no parameter.
If seed = 0 Then seed = Timer
Dim c As Integer
Dim d As Integer
Dim lenString As Integer
Dim tmp As String
' little known 'trick' with rnd and randomize keywords.
' call rnd with any negative parameter
Rnd (-1)
' then call randomize with any positive seed
Randomize seed
' and the sequence of random numbers will always be the
' same. We ensure the sequence is different each time
' the app is run by using the timer as out seed. If we
' use a constant value instead, then the "random" sequence
' will forever be the same
' generate 10 to 30 strings
For c = 1 To Rnd() * 20 + 10
tmp = ""
' get a random length between 5 and 15 chars
lenString = Rnd() * 10 + 5
For d = 1 To lenString
' get a random char form A to Z
tmp = tmp & Chr(Rnd() * 25 + Asc("A"))
Next
' add string to listbox
List1.AddItem tmp
' print string also
Debug.Print c, tmp
Next
End Sub
Hope it helps
Reset udtA.DONEGENERATE to 0 again
Based on what I see in your sample, I suspect you are not resetting your udtA.DONEGENERATE value to 0.
This would prevent your code from generating the strings. Don't be fooled by the fact that your combo boxes are empty. This is due to the form being reloaded so of course they will be empty.
You will also improve your code a whole bunch by implementing Select Case instead of your if statement block.
Think about the value of your RAN variable. Can it ever equal 0 and 1 at the same time? If not (and I assure you it cannot) then you are wasting time in your code by asking whether RAN = 0 to 7 when we know that only one of these will be true.
change the if statements to:
Code:
Dim RAN As Integer
RAN = Int((8) * Rnd)
Select Case RAN
Case 0 To 3
Employeez.AddItem ("Manual Labourer")
Case 4, 5
Employeez.AddItem ("Bodyguard")
Case 6
Employeez.AddItem ("Scientist")
Case 7
Employeez.AddItem ("Navigator")
End Select
Counter = Counter + 1
Finally, before my advice is over, you only need to call Randomize once in your sub. Put it outside the loop (above the do statement is fine).
Get into the habit of using Dim to decalre all variables. To get you into the habit, click "Require Variable Declaration" in the Tools | Option dialog in VB.
Sorry to lecture you - I hope it helps you though.
Regards
Try out my previous example
You will find that in my example, it is always the same sequence of "random" numbers each time you click the button. After you close the app and restart it, a new sequence will occur.
Regards