Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form
Changing Display in Main Form Changing Display in Main Form
Changing Display in Main Form
Go Back  Xtreme Visual Basic Talk > > > Changing Display in Main Form


Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2002, 10:55 AM
velicity13
Guest
 
Posts: n/a
Question Changing Display in Main Form


Thanks to all in advance,
Im new to VB and Im working on an application which has a rolling counter on the main form that basically displays the current line number being processed by the code. Im wondering what is the best method to display a rapidly changing text inside of the main form. The methods that I have used so far don't display anything until the code is completely finished with all of the lines, then it shows the final number. I tried opening a second, smaller, form over the first one that shows this information and uses CLs on that form just before updating the counter being displayed. From the sketchyness of the screen at that point I can clearly see that this is not the best way. I have been all through the VB help about every kind of display method and I just seem to be missing some little thing. Thanks again.
Reply With Quote
  #2  
Old 03-03-2002, 10:58 AM
ThinkerChanging Display in Main Form Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

It might be as simple as including a DoEvents inside the loop
processing the lines. Right after you update whatever control
(label.caption, I assume) you put a line with just DoEvents. Of
course, this will slow down the processing, so you would have to
decide whether it was better to show a counter and have it run
slower, or faster without any counter. Another method, if you
know the total number of lines to be processed ahead of time,
would be a progressbar.
__________________
Posting Guidelines
Reply With Quote
  #3  
Old 03-03-2002, 11:00 AM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

What kind of object are you using to display the changing number? It may be easier for us to help you if we can see the code you are using.

Good Luck,
Orbity
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #4  
Old 03-03-2002, 11:12 AM
velicity13
Guest
 
Posts: n/a
Default

Ok, theory wise, Its not imperative that I display a counter but as soon as I realized that I couldn't successfully do it I had to figure it out.
My first attempt used the main form with a single line "text box" which I would address each time the code processed a line.

do
(process line activity)
(so on)
(so forth)
line = line + 1
frmMain.text = line
loop

With that type of addressing I was only able to view the (line) value in the text box after the entire process was complete. I didn't understand why the information isn't always displayed when it is told to. Im a Basic programmer from way back and Im having a bit of trouble with the event driven theory of programming.
Reply With Quote
  #5  
Old 03-03-2002, 11:16 AM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Try using a label to do this, I have found that in my limited experience TextBoxes don't work well with doing this .

HTH,
Orbity

P.S. Try it without the DoEvents first.
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #6  
Old 03-03-2002, 11:27 AM
velicity13
Guest
 
Posts: n/a
Default

Thanks for the quick responses.
I tried placing a label on the main form that displayed the counter and it, not unlike the text box, did not respond by displaying anything until the processing was done. Just for diagnostic testing I used a simple print command to let me know if the line number was actually going anywhere and it scrolled down nicely in the background of the main form as the code ran so I know that things are processing properly. I also tried a print command and locating the actual coordinates of where I wanted the counter to display but I had to CLs the form before each increment or else I would end up with some funky little stain in that spot as the numbers would just run over eachother. Unfortunately I don't know the size of the list being processed as I am receiving the lines via RS-232 from another computer that doesn't have the capability to transmit file size. It just has a dump command. I understand that in Windows programming my code does not own the processor as it did when I was a dos programmer and I am wondering if I have this problem because Im missing some type of command that is used to force the text to be displayed as opposed to being delayed. ?
Reply With Quote
  #7  
Old 03-03-2002, 11:40 AM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

I must admit that I have never had this problem. Everytime I have needed to show some results they always displayed without a problem. Here is how I do it:
Code:
'process line activity
Do While LineNum <= 1000
    'so on 
    'so forth) 
    LineNum = LineNum + 1 
    lblLineNumber.Caption = LineNum 
Loop
Maybe we are both missing something here

HTH,
Orbity
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #8  
Old 03-03-2002, 11:45 AM
Squirm's Avatar
SquirmChanging Display in Main Form Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Yes, possibly a DoEvents call.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #9  
Old 03-03-2002, 11:58 AM
velicity13
Guest
 
Posts: n/a
Lightbulb

Ok guys, once again, thank you for the rapid responses. If I use a DO EVENTS loop does that force windows to "notice" the events that are caused by my code as opposed to being behind the scenes? Therefore If I request to display something in real time I actaully have the attention of Windows where as I will get the display result that I expect? Possibility?
Reply With Quote
  #10  
Old 03-03-2002, 12:03 PM
ThinkerChanging Display in Main Form Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

DoEvents is not a loop, it is a command to tell windows your
process is releasing the rest of its time-slice. It gives windows a
chance to process other messages that would otherwise just pile
up waiting for an opportunity, like the ones that would allow the
text in the label.caption to display.
__________________
Posting Guidelines
Reply With Quote
  #11  
Old 03-03-2002, 12:09 PM
ThinkerChanging Display in Main Form Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

As an example...
Code:
Do 
  (process line activity) 
  line = line + 1 
  frmMain.lblProcessed.Caption = line 
  DoEvents
Loop 
<Or if that slows things down too much>
Do 
  (process line activity) 
  line = line + 1 
  frmMain.lblProcessed.Caption = line 
  If Not CBool(line Mod 100) Then DoEvents 'Once every 100 lines
Loop
__________________
Posting Guidelines
Reply With Quote
  #12  
Old 03-03-2002, 12:43 PM
velicity13
Guest
 
Posts: n/a
Default

Excellent information! Fear not, these kinds of explainations are not lost. I am learning very rapidly here. Ok, so if I want Windows to perform functions such as displaying text in real time, according to my code, then I should use DoEvents within that portion of code. Now, I will assume that overuse of a call to DoEvents is unnecessary and will probably reek havok with other applications that may be running at the same time. What other types of events in VB programming will require the use of DoEvents besides modifying the display of a form, box, label, etc? Moreover, what types of events should I try to keep a DoEvents call out of for the sake of friendly processing?

thank you!
Reply With Quote
  #13  
Old 03-03-2002, 12:49 PM
velicity13
Guest
 
Posts: n/a
Default

As a side note I had intended to tell you guys that during experimenting I found that my text to and messages to be displayed in other parts of my program were delayed and would pop up at rather erratic times. I quickly learned that if I forced my program to stop for some reason (ie. messagbox) then my text would be immediatly displayed as well as the message box. I guess I knew that processing of other operations by Windows was the root of my problem.
Reply With Quote
  #14  
Old 03-03-2002, 06:19 PM
ThinkerChanging Display in Main Form Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Quote:
Now, I will assume that overuse of a call to DoEvents is unnecessary and will probably reek havok with other applications that may be running at the same time.
No, not at all. The only effect will be to slow down the process
overusing the DoEvents. So, avoid overuse to keep your app
running as quickly as possible, but use where you need to allow
windows some system processor time (this means inside of tight
loops.)
__________________
Posting Guidelines
Reply With Quote
  #15  
Old 03-03-2002, 06:25 PM
Squirm's Avatar
SquirmChanging Display in Main Form Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Cool Yes and No

The only time I found DoEvents to be a problem is when dealing with control events. Specifically the winsock control springs to mind. I do all my data checking and parsing without DoEvents for the reason that, should I put one in, the event might fire again before the previous data had been properly handled, causing data to be overwritten and all kinds of problems.

But for tight loops that will take time, or that rely on some outside event to terminate the loop, then a DoEvents is a must.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #16  
Old 03-03-2002, 06:44 PM
ThinkerChanging Display in Main Form Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Very good point Squirm, thanks for correcting my over-simplification.
__________________
Posting Guidelines
Reply With Quote
  #17  
Old 03-03-2002, 06:50 PM
Banjo's Avatar
BanjoChanging Display in Main Form Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default

Sometime you can not avoid using a DoEvents from a DataArrival event. My example is that I use a generic progress display form which requires a DoEvents for when it is used in a tight loop.

In this case you can use a method of storing a the incoming data in a static string and then parsing it. If the event fires again then you store the data in the static and exit to let the first instance of the event function will continue parsing the new data when it finishes the data it was originally dealing with.
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
Reply


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

Advertisement:





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.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
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..
subscribe
Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form Changing Display in Main Form
Changing Display in Main Form
Changing Display in Main Form
 
Changing Display in Main Form
Changing Display in Main Form
 
-->