PDA

View Full Version : How to update value to a textbox according to loop-index



arrun
12-04-2007, 12:01 AM
I have created a 'for' loop with index j. Now I want to track the value of j when this loop is running. For this purpose I have created a textbox. The value of textbox will be the value of j. my code is like that :

for j = 1 to 6
textbox2.value = j
...............
............
next j

However I am not getting what i wanted. This textbox only showing the last value of j, not intermediate values of j. Can anyone tell me where I am making mistake?

Thanks in advance

mikerickson
12-04-2007, 01:09 AM
It's setting the value to 1, then to 2, then to 3,... and finally to 6, very quickly.

What do you want the value to be?

arrun
12-04-2007, 01:36 AM
If there is any change (at all) it is not visible. Is there any possibility to make the process little bit slower, so that it can be possible to see in textbox at least? I have to do that, because my boss feels that, there is no change in my code at all!

Thanks,

Bob Phillips
12-04-2007, 01:55 AM
ADjust the k loop to suit



Private Sub cmdOK_Click()
Dim j, k
For j = 1 To 6
For k = 1 To 10000000
Next k
DoEvents
TextBox2.Value = j
'...............
'............
Next j
End Sub

arrun
12-04-2007, 01:59 AM
One question please ! what is the utility of 'DoEvents ' here? Can you please explain?

Bob Phillips
12-04-2007, 02:01 AM
The loop is a bit tight and takes over, so I added DoEvents so that the form painting gets a look in.

Bob Phillips
12-04-2007, 02:01 AM
To clarify, without it, all of the intermediate values don't show, it only re-paints the form when the loop finishes, when the j value is 6.

arrun
12-04-2007, 02:35 AM
Thank you Xld for your help. My problem has been solved. However any other suggestion also welcome.

With Regards,