• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

VB 6, Form do not show until a certain time

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
maquejph
Asked:
maquejph
1 Solution
 
aelatikCommented:
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
 
TimCotteeCommented:
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
 
DocMCommented:
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!

 
maquejphAuthor Commented:
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
 
YahikoCommented:
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
 
maquejphAuthor Commented:
Using Doevents ?

You mean create a sub that use timer to slow the application?
0
 
maquejphAuthor Commented:
Using Doevents ?

You mean create a sub that use timer to slow the application?
0
 
YahikoCommented:
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
 
maquejphAuthor Commented:
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
 
maquejphAuthor Commented:
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
 
maquejphAuthor Commented:
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
 
YahikoCommented:
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
 
maquejphAuthor Commented:
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
 
maquejphAuthor Commented:
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
 
YahikoCommented:
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
 
supunrCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now