It is 'Application.DoEvents' in VB2008
Some background:
1) Visual Basic (prior to the .NET versions, such as VB2008) was a single-threaded application. Without going in to the full complexity, this means that whilst your program is doing one thing it cannot also be doing another. So, if you are zipping around a loop you cannot do something else in your program at the same time - like respond to a button click and set a variable. DoEvents exists (amongst other things) to allow certain different part of your program to run. In particular it allows GUI events, such as button presses, to be responded to.
2) .NET versions of VB, such as VB2008 (I'll just say VB2008 from now on), were designed to be a bit like traditional VB in order to make the transition for VB programmers as painless as possible (the successof this strategy is arguable). As a result, typically VB2008 programs run in a single thread, just like tradional VB programs, and traditional way to get the GUI to be responsive still exists: DoEvents.
3) VB2008, however, is not really like traditional VB. It is builtr on the Common Language Runtime, and every command comes from a library (or 'namespace'). Many of the commands therefore have to be explicitly referenced using the name of the library/namespace (from now on I'll just say namespace) to ensure that the right one is used.
4) In VB2008 the DoEvents command is in the Application namespace, so to use it you need to be explicit as follows:
Application.DoEvents
So, here's a short VB2008 program illustrating the technique. You'll require a form and two buttons:
Code:
[blue]Public Class Form1
Private EndLoop As Boolean = False ' EndLoop variable visible by all subs/functions in this module
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Loopy() ' start our never-ending loop
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
EndLoop = True ' Flag loop to stop
End Sub
Private Sub Loopy()
Dim lp As Long
Do Until EndLoop ' Check to see if we have flagged loop to stop
lp = (lp + 1) Mod 100
TextBox1.Text = lp
Application.DoEvents() ' allow certain other threads to run by processing all Windows messages currently in the message queue - allows GUI events to occur
Loop
MsgBox("Loop successfully terminated")
End Sub
End Class[/blue]