Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can VB execute code line-by-line

Status
Not open for further replies.

rombosiaj

Programmer
Jun 10, 2005
7
KE
Hi tek-tip pals,
Is there any way for VB to execute code line-by-line like in the compiler languages? I mean,
if, for example I have a form with a command button and a label
then I apply this code to the command_click function:
For t = 0 To 20000
myLabel.Caption=Cstr(t)
Next t

The only time the label will display anything is when the entire
process is finished. How can I make it execute each line completely
before it executes another because in an application, the user needs
to know what's happening.
Thanks.
 
Try this
Code:
 For t = 0 To 20000
  myLabel.Caption=Cstr(t)
  myLabel.Refresh
  DoEvents
 Next t
 
Wouldn't you have the same problem with:
Code:
for(t=0;i<=20000;t++)
{itoa(t, myLabel.Caption, 10);}



 
The F8 button lets you run the code line by line.
 
No, it wasn't VB6.

I think Sheco's point was that this isn't an "execution" issue at all.

It isn't even a "single step" issue, even though the title of this thread would tend to lead on down this path.

The problem here has everything to do with the way updates to the visible window are done when a program is burning cycles in a tight loop. And this is one of the reasons for having DoEvents in VB in the first place.

You can see the very same thing in a browser running script that repeatedly updates visible elements on the page. Unless you make your script "take a breath" the actual rendered page never gets updated until after the script stops running.

Trickier there of course, neither VBScript nor Javascript offer anything like DoEvents and there isn't such a function exposed by the browser object model either. A real shame too.

In such cases I have often resorted to some real convolutions. Typically you have to break up your script into multiple event handlers, tying later pieces to the earlier ones by setting timers and such via operations like window.setTimeout().

Ah, the much-maligned (and often misused) DoEvents() function. Yes, it's a function - not a statement.

DoEvents Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top