Looping in programming is very powerful, but sometimes looping can be an annoying function if we use it wrong.
Looping can make our program stop responding or loops forever.
How can those things happen?
Here the simple example of looping forever:
a = 1
For i = 1 to b
If a = 1 then b = b + 1
Next i
As long as “a” still have value “1” then looping can’t be stop.
Here another example:
a = 100000000
For i = 1 to a
If a = 800000 then exit for
a=a+1
Next i
As long as “a” still not have value “800000” then loops again. You can see how long the loops can be. The impact is the program is like stop responding and we can’t do anything on that software
In visual basic, we can use “doevents” statement to control unexpected loops.
Doevents allows us to control our program even loops still running, so our program not stops responding.
Here the example of using doevents:
rs.movefirst
For i = 1 to rs.recordcount
If rs![name] = “newbiprogrammer” then exit for
rs.movenext
doevents
Next i
The code shows us to search the name of “newbieprogrammer” and then get off from the loop function, but as long as the name not have value like that, loops will continue looping and searching with the recordset. The code will not get stop responding as long as we have the doevents function.
Ok.. try it..
Enjoy it

0 comments:
Post a Comment