?
Solved

VB 6, Form do not show until a certain time

Posted on 2003-03-31
16
Medium Priority
?
178 Views
Last Modified: 2010-05-01
Hello,

Description: I have a form with 2 label on it. on event Form_Load, I call a Sub that Retrieve using FTP a large text file (10mo), then when the file is on the local disk, I read that file line by line. In the sub that read the file I update the Label2.Caption with the content of the line (So I can see the progress...Some kind of debug)

Problem: The form appears on the screen when everything is done ..., it does not even appears in the task bar. Can see it running in the process/applications in the task manager ...

Code:
Private Sub Form_Load()
    Main.Label1.Caption = ""
    Main.Label2.Caption = ""
    Main.Label1.Caption = "Waiting retrieve the file (ftp)"
    Main.Refresh
    RetrieveTheFile
    Main.Label1.Caption = "File retrieved!"
    Main.Refresh
    AnalyzeTheFile
    Main.Refresh
End Sub
Private Sub RetrieveTheFile
    ...
    ...    
End Sub
Private Sub AnalyzeTheFile()
    Main.Label1.Caption = "Analyzing the file(" & sLocalPathName & sLocalFileName & ")"
    Main.Label2.Caption = ""
    Main.Refresh
    Open sLocalPathName & sLocalFileName For Input As #1
    While Not EOF(1)
        Line Input #1, temp$
        Main.Label2.Caption = ""
        Main.Label2.Caption = temp$
        Main.Refresh
    Wend
    Close #1
End Sub
0
Comment
Question by:maquejph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
16 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 8237543
Place a timer control and use the following code...


Private Sub Form_Load()
Timer1.Interval = 2000
Timer1.Enabled = True
End Sub
Private Sub RetrieveTheFile()
   ...
   ...
End Sub
Private Sub AnalyzeTheFile()
   Main.Label1.Caption = "Analyzing the file(" & sLocalPathName & sLocalFileName & ")"
   Main.Label2.Caption = ""
   Main.Refresh
   Open sLocalPathName & sLocalFileName For Input As #1
   While Not EOF(1)
       Line Input #1, temp$
       Main.Label2.Caption = ""
       Main.Label2.Caption = temp$
       Main.Refresh
   Wend
   Close #1
End Sub

Private Sub Timer1_Timer()
Call StartOps
Timer1.Enabled = False
End Sub

Function StartOps()
   Main.Label1.Caption = ""
   Main.Label2.Caption = ""
   Main.Label1.Caption = "Waiting retrieve the file (ftp)"
   Main.Refresh
   RetrieveTheFile
   Main.Label1.Caption = "File retrieved!"
   Main.Refresh
   AnalyzeTheFile
   Main.Refresh
   Timer1.Enabled = False
End Function
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 8237546
Hi maquejph,

Don't do it all in form_load.

If this is the startup form, consider using Sub Main to start you application. Place the code from form load into a public sub on the form and call that immediately after showing the form in form_load.

By default the form will not show until *ALL* processing in Form_load has been completed. If you seperate this out then you can get it to display your updates.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
 
LVL 3

Expert Comment

by:DocM
ID: 8237551
HI,
Use the Show command early:

Private Sub Form_Load()
Main.Show 'or Me.Show
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:maquejph
ID: 8237584
Well, guys that for the fast answers :)

So I use the Main.show into my Form_load()
and move the code into a new sub that is called into the form_load.

A mix of your answers :)

I have another problem (same kind I suppose)
The application freeze the display (not responding)
So it start and then it freeze (but it is still running ...) after sometimes it unfreeze ... I have created another application that list very long network drive tree folder and I have the same behavior ...
0
 

Accepted Solution

by:
Yahiko earned 200 total points
ID: 8237591
The problem is that your program is a processor intensive process, and doesn't give anytime to windows to update your form. This can be changed by using Doevents, at the end (of beginning of your loop). This gives your Operating System a cycle to do an update.
0
 

Author Comment

by:maquejph
ID: 8237661
Using Doevents ?

You mean create a sub that use timer to slow the application?
0
 

Author Comment

by:maquejph
ID: 8237679
Using Doevents ?

You mean create a sub that use timer to slow the application?
0
 

Expert Comment

by:Yahiko
ID: 8237697
No, DoEvents is a standard function in Visual Basic.
If you are working with Visual Basic .Net, you'll have to do Application.DoEvents.

Just try it out. It really works. There is only one disadvantage, and that is that the user can perform other actions, like clicking other buttons etc...
0
 

Author Comment

by:maquejph
ID: 8237749
I'm with VB 6

BW, this application is very short and do not have needs of user intervention ... so no button or stuff :) The label are just there to show the progress.

In fact a made some debug now and I saw that it freeze at the: Line Input #1, temp$
It seems that it can not find the end of the line (crlf)and so it read the whole file in once!
If I open the file with a text editor like UEdit it work well I saw the lines ... But If I open it with notepad it is a mess ...

Anybody got that behavior before?
0
 

Author Comment

by:maquejph
ID: 8237764
I'm with VB 6

BW, this application is very short and do not have needs of user intervention ... so no button or stuff :) The label are just there to show the progress.

In fact a made some debug now and I saw that it freeze at the: Line Input #1, temp$
It seems that it can not find the end of the line (crlf)and so it read the whole file in once!
If I open the file with a text editor like UEdit it work well I saw the lines ... But If I open it with notepad it is a mess ...

Anybody got that behavior before?
0
 

Author Comment

by:maquejph
ID: 8237779
I'm with VB 6

BW, this application is very short and do not have needs of user intervention ... so no button or stuff :) The label are just there to show the progress.

In fact a made some debug now and I saw that it freeze at the: Line Input #1, temp$
It seems that it can not find the end of the line (crlf)and so it read the whole file in once!
If I open the file with a text editor like UEdit it work well I saw the lines ... But If I open it with notepad it is a mess ...

Anybody got that behavior before?
0
 

Expert Comment

by:Yahiko
ID: 8237820
Try to open it with notepad. Probably the problem is that the file has a Linux format, where a new line is just \n while in windows it is \r\n (vbcrlf). UEdit probably notices this, so it just handles the file that way.

0
 

Author Comment

by:maquejph
ID: 8237832
I'm with VB 6

BW, this application is very short and do not have needs of user intervention ... so no button or stuff :) The label are just there to show the progress.

In fact a made some debug now and I saw that it freeze at the: Line Input #1, temp$
It seems that it can not find the end of the line (crlf)and so it read the whole file in once!
If I open the file with a text editor like UEdit it work well I saw the lines ... But If I open it with notepad it is a mess ...

Anybody got that behavior before?
0
 

Author Comment

by:maquejph
ID: 8237907
Well the solution was there ... The file format= Unix !
So I have forced the ftp download to ASCIII ... Now, it read well line by line ...

I still have that freeze problem ...
Application.DoEvents is not recognized...
I Try to use Main.Show into my loop :) bad idea :)
It was stuck on top, I was able to see the lines changing but I was not able to kill the applic :)
Well ...
0
 

Expert Comment

by:Yahiko
ID: 8237958
You said you are working with VB6, then you'll have to do Doevents, not Application.Doevents (thats for the .NET)

And my guess was right, it was in Unix format :)
0
 
LVL 11

Expert Comment

by:supunr
ID: 8238234
Private Sub Form_Load()
   show  '<- show the form here
   ' or
   visible = true ' <- if the form is a modal form
   doevents '<- give time to refresh the form
   Main.Label1.Caption = ""
   Main.Label2.Caption = ""
   Main.Label1.Caption = "Waiting retrieve the file (ftp)"
   Main.Refresh
   RetrieveTheFile
   Main.Label1.Caption = "File retrieved!"
   Main.Refresh
   AnalyzeTheFile
   Main.Refresh
End Sub

' Good Luck!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question