Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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

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
brian_appliedcpu
Asked:
brian_appliedcpu
  • 9
  • 8
  • 6
  • +1
1 Solution
 
JR2003Commented:
Can you paste your looping code in here?
0
 
brian_appliedcpuAuthor Commented:
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
 
BurbbleCommented:
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
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.

 
MrPanCommented:
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
 
BurbbleCommented:
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
 
JR2003Commented:
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
 
JR2003Commented:
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
 
BurbbleCommented:
The SlowDown() routine that I posted contains a DoEvents in it, and eliminates the need to use the Script object...

-Burbble
0
 
brian_appliedcpuAuthor Commented:
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
 
JR2003Commented:
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
 
brian_appliedcpuAuthor Commented:
Is there no way it can read the line of code by itself?
0
 
JR2003Commented:
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
 
brian_appliedcpuAuthor Commented:
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
 
JR2003Commented:
put
Unload Form1
at the end of the module
0
 
brian_appliedcpuAuthor Commented:
cool thanks...
especially for the quick responses
0
 
BurbbleCommented:
>> 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
 
brian_appliedcpuAuthor Commented:
Can you point me to the built in methods, should I open a new question?
0
 
BurbbleCommented:
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
 
brian_appliedcpuAuthor Commented:
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
 
BurbbleCommented:
>> 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
 
brian_appliedcpuAuthor Commented:
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
 
BurbbleCommented:
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
 
brian_appliedcpuAuthor Commented:
I did what you suggested and even though the form closes the program continues until it is finished
0
 
BurbbleCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 9
  • 8
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now