Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > how to force VB to strickly execute code line-by-line

Thread Tools Display Modes
Old 04-19-2012, 01:56 PM
StorM_GmA StorM_GmA is offline
Join Date: Oct 2007
Posts: 96
Default how to force VB to strickly execute code line-by-line

I'm writting a program for sorting and editing (large) text files containing lists of random words. During the process, i've used a text field that informs the user in which stage the process is. The code is something like this (i won't paste the actual code because it's not necessary and it's hard to read) when the user presses the button to start the process:

print "Opening file..." in textfield
open .txt file for input
print "file opened successfully" in textfield
print "reading records..." in textfield
Do While loop to save .txt records into an array
print "Sorting..." in textfield
save current time
run QuickSort3 module to sort the array
save current time
print the DateDiff in textfield

The problem here is that VB is getting ahead of the commands so when I press the button to begin the above process, the program freezes for few seconds (which means it is running the sorting algorithm) and then prints everything in the textfield at once. Even the two "save current time" are saving the exact same time no matter how long it took for the sorting algorithm to do it's job.

I have tried to use "DoEvents" in many places in the code with no luck. So, how can I force VB to execute the code line-by-line? I want to see the text in the textfield before the program starts sorting the array!

thank you for your time!
Reply With Quote
Old 04-19-2012, 03:04 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,977

Don't use DoEvents.
Try as .Refresh on the control you're printing in so it updates before you continue.
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Old 04-20-2012, 05:57 AM
StorM_GmA StorM_GmA is offline
Join Date: Oct 2007
Posts: 96

wow...that was weird! I tried to refresh the textbox just before the sorting function and it didn't seem to fix the problem. I started replying here telling that it didn't work when I thought to add one more textbox.refresh right before saving the .txt records to the array and voila!

It turns out, it takes much more time to read a (213.000 records) .txt and store it into an array than making like a gazillion loops to sort it. I just wrote these so othens can know!

Thanks passel for your help!
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..