Solved

HELP 500pts VB app freezes ..sometimes, I need dialog box showing current line of code

Posted on 2004-08-23
24
198 Views
Last Modified: 2010-05-02
I have an appication that I have written in VB6 and compiled into an exe.
The program runs in a wscript loop every 1 min.
Occationally the program will just freeze and take up 50% of the processor.
I have put some on error code in writing the errors to a file and this works fine as when it errors, it writes the error and it exits. ...except when it freezes.  I am at a loss of what to do.

Is it possible to create, (i am very new at this) a form since the only item in my program is a module, that will display the current line of code that the program is on....so when it freezes, i can see where it froze.
I can run it in debug mode till i am old and grey and it works fine and it may cycle 1000 times without freezing but then on the 1001 time it locks.
0
Comment
Question by:brian_appliedcpu
  • 9
  • 8
  • 6
  • +1
24 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 11870977
Can you paste your looping code in here?
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11871044
Dim strFile01, oWshShell
strFile01="MyProg.exe"
Set oWshShell = WScript.CreateObject("WScript.Shell")

do
   intReturn01 = oWshShell.Run(strFile01, 1, TRUE)
   WScript.Sleep(60000) ' 1000 = 1 second
loop
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11871104
Try this "Sleep" routine instead:

Private Declare Function GetTickCount Lib "kernel32" () As Long

Public Sub SlowDown(MilliSeconds As Long)
    Dim lngTickStore As Long
    lngTickStore = GetTickCount()
    Do While lngTickStore + MilliSeconds > GetTickCount()
        DoEvents
    Loop
End Sub

Call it like this:  SlowDown(60000)

Also, is there any reason to use the Scripting object at all? You could do this:

Dim strFile01 as String

strFile01 = "MyProg.exe"

Do
    Shell strFile01, vbNormalFocus
    SlowDown(60000)
Loop

-Burbble
0
 
LVL 2

Expert Comment

by:MrPan
ID: 11871126
There is no exit in the loop. It will loop forever. I would add a doevents() into the loop so the rest of the machine can get some processor. I assume that the code should be something like

Do while intReturn <> 0
   doevents()
   intReturn01 = oWshShell.Run(strFile01, 1, TRUE)
   WScript.Sleep(60000) ' 1000 = 1 second
loop

0
 
LVL 7

Expert Comment

by:Burbble
ID: 11871135
Oh, or if you need the return of Shell() then use this:

Dim strFile01 as String
Dim intReturn01 as Double

strFile01 = "MyProg.exe"

Do
    intReturn01 = Shell(strFile01, vbNormalFocus)
    SlowDown(60000)
Loop

-Burbble
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11871180
You definitely need a doevents in there. Try this.

do
   intReturn01 = oWshShell.Run(strFile01, 1, TRUE)
   DoEvents
   WScript.Sleep(60000) ' 1000 = 1 second
   DoEvents
loop
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11871205
Or even better:

do
   intReturn01 = oWshShell.Run(strFile01, 1, TRUE)
   DoEvents
   WScript.Sleep(10000) ' 1000 = 1 second
   DoEvents
   WScript.Sleep(10000) ' 1000 = 1 second
   DoEvents
   WScript.Sleep(10000) ' 1000 = 1 second
   DoEvents
   WScript.Sleep(10000) ' 1000 = 1 second
   DoEvents
   WScript.Sleep(10000) ' 1000 = 1 second
   DoEvents
   WScript.Sleep(10000) ' 1000 = 1 second
   DoEvents
loop
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11871228
The SlowDown() routine that I posted contains a DoEvents in it, and eliminates the need to use the Script object...

-Burbble
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11871390
Thank you for the rapid responese, however the wscript is not freezing the MyProg.exe is.
Can we go back to the original question please?
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 500 total points
ID: 11871731
Yes sure, just add a form to your code with a label on it.

Then in your code module at the begining put
    Form1.Show

Then at regular intervals put something like:
    Form1.Label1.Caption = "I am at Line 1234"
    Form1.Label1.Refresh
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11871766
Is there no way it can read the line of code by itself?
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11871905
Nope, unless it's actually erroring then you could use Erl to give you the line number causing the error. Even using this though you have to get all your lines numbered for it to work.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11872027
Ok...I tested what you suggested and since the program runs every minute or so, i need it to close the form after the program completes.
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11872205
put
Unload Form1
at the end of the module
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11872223
cool thanks...
especially for the quick responses
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11872496
>> however the wscript is not freezing the MyProg.exe is.

The Program is using the Script object, and if it was having a problem, then the Program would inherit it. The use of the Script object may also be taking up unnecessary resources, since you can accomplish the same task using the built-in methods of Visual Basic and API.

Also, since you have seen that the Script object may be unreliable when looped excessively, it may be wise to switch to a different method that is less error-prone.

That's all :-)

-Burbble
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11872530
Can you point me to the built in methods, should I open a new question?
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11872590
This is what I posted before, uses the GetTickCount API and the Shell() method:

-----
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub SlowDown(MilliSeconds As Long)
    Dim lngTickStore As Long
    lngTickStore = GetTickCount()
    Do While lngTickStore + MilliSeconds > GetTickCount()
        DoEvents
    Loop
End Sub

Private Sub ExecuteFunction()
    Dim strFile01 as String
    Dim intReturn01 as Double

    strFile01 = "MyProg.exe"
    Do
        intReturn01 = Shell(strFile01, vbNormalFocus)
        SlowDown(60000)
    Loop
End Sub
-----

I just don't see the need to use a Script object for this? Maybe there is other code in the module that relies on it...

-Burbble
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11872643
So what you are proposing is a seperate exe to call myprog.exe?
Can we not put the looping inside the myprog.exe and put a "End Program" button on the Form?
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11872739
>> So what you are proposing is a seperate exe to call myprog.exe?

That's not what you have already? lol, I feel so confused :-/

I think it's best that we all just ignore me.

-Burbble
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11872771
No I had a wscript.vbs with the following code in it.
Dim strFile01, oWshShell
strFile01="MyProg.exe"
Set oWshShell = WScript.CreateObject("WScript.Shell")

do
   intReturn01 = oWshShell.Run(strFile01, 1, TRUE)
   WScript.Sleep(60000) ' 1000 = 1 second
loop


***** Is there a way to have the program loop within itself without using a wscript?
And then put a "End Program" button on the Form?
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11872837
It depends on what MyProg.exe is doing. You cannot have it calling itself, but you could loop whatever action it is performing. Was there a specific reason for writing a separate Script to load it every minute?

An "End Program" button is simple: Dimension a boolean variable and then set it to True when you click the command button... like this:

Dim EndNow as Boolean

Private Sub Command1_Click()
    EndNow = True
End Sub

And then change the Loop so I looks like this:

Do While EndNow = False
...
Loop

-Burbble
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 11873549
I did what you suggested and even though the form closes the program continues until it is finished
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11874702
Oh, add this to the Form_Unload event:

Unload Form1
Set Form1 = Nothing

...and if that doesn't fix it, add End in addition to the above.

-Burbble
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now