For Next loop logic

kenneth.campos

Registered User.
Local time
Today, 19:06
Joined
Jan 2, 2010
Messages
11
My code:
Code:
Dim rfoct As Integer
For i = 1 To 5
rfoct = Int((999 - 100 + 1) * Rnd + 100)
Form_MyForm.MyField = rfoct 
Next i
I want to see each number, then have it overwritten by the next number. Slow enough to see the number. Right now the loop either goes so fast or I only get the last loop to output to the form. I want to be able to see each loop output.
 
add a loop with a timer like this:
PHP:
        pausectrl = Timer
        Do Until Timer >= pausectrl + NumberOfSecondsVariable
        Loop
 
Thanks for the reply!

This code seems to work properly, however the Form_MyForm.MyField is still not outputting to the field until after all the loops have run. I changed it to msgbox, and a msgbox popped up with the random numbers each time, however once i changed it back, it went back to populating only the last number after it had finished all the other for next loops.
 
maybe you need to requery the form each time? How many seconds are you using with the timer? You might be using enough seconds too.
 
The form doesn't refresh until after the code is done so you only see the last value. If you want to refresh the whole form do:

Form_MyForm.refresh


But you probably only need to refresh the field you've updated:

Form_MyForm.MyField.Refresh
Hope this helps.
-Lution
 
Thanks for the replies!

Form_MyForm.Refresh was close, it was .Repaint that did the trick. Form_MyForm.MyField.Refresh/Repaint errors.

Thank you very much.
 
you will probably find that doevents would also repaint the sscreen
 
Heres another one.

I want to do something like this

For i = 1 to 5
myVari = whatever
Next i

So that i end up with 5 variables, myVar1 through myVar5, all as whatever.
 
Kenneth,

If the target "myvari" is a variant:

Code:
Dim myvari As Variant

For i = 1 to 5
   myVari(i) = whatever
   Next i


Or an array:

Code:
Dim myvari(5) As String

For i = 1 to 5
   myVari(i) = "whatever"
   Next i

Or form controls:

Code:
For i = 1 to 5
   Me.controls("TextBox" & CStr(i)) = "whatever"
   Next i

hth,
Wayne
 

Users who are viewing this thread

Back
Top Bottom