Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

visual basic 6 timer problem

Posted on 2009-04-21
32
Medium Priority
?
5,054 Views
1 Endorsement
Last Modified: 2012-05-06
This may or may not be a Visual Basic timer problem, but as the "problem" seems to circle around it I will try my best to explain the problem.

First of all, my application uses 2 timers. For my debuging code all I do is place a textbox in my application and each timer just prints to the text box "TIMER 2" or "TIMER 4". Its just an easy way to verify the timers are working..

Now next up, is this all works fine in the VB6 editor, however, it always fails on a compiled exe.

On the compiled program, the timers both run for a few seconds, and timer 2 just simply stops. Timer 4 carrys on and I added in there a textbox debug which reports timer2 is enabled and the tick is 1000. However, timer2 I have just placing the words "TIMER 2" in the text box and it does not do it after a few seconds, even though timer 4 still functions and still reports timer 2 is enabled and the tick is 1000.

Now before you jump in with ideas please read this carefully...

Now I do have a GO and STOP button on my form, which can enable and disable both timers.. all works fine. When the timers are running it uses about 25% CPU power (the code does  a lot so no problems there). Now when the timer 2 "stops" it runs the CPU to 100% and it appears the application has crashed and locked up. which I think it has at this point..

timer 4 is still running, still reports timer2 is enabled and tick is 1000. BUT... now when I click the STOP button which disables both timers.. the CPU is still maxed out.. if I click START again nothing happens..

Now this is not a fault in the code, as if you let the program cycle a couple of times, then STOP it, and START it again with the buttons, it works fine and cpu drops to zero as nothing is running.

This is a very difficult problem to explain, but the best way I can explain it is that the program partically crashes and timer2 stops working then maxes out the CPU.

Furthermore, when you try to exit the application, it actaully reloads itself which is really bizzare. But if you run the program a few seconds (before this "crash" problem) then close it, it all closes down correct.

But if you leave it running until this timer crash problem and try to quit the application, it just keeps reloading itself. then have to just end-task it.

Once this "timer crash" happens, the program does not function correctly at all. It can't function without timer2 operating, but as its not being triggered it shouldn't be using a high CPU useage. So I can only explain it as some strange partial crash.

again, the program will run for hours in the VB6 editor with no problems, but as soon as it is compiled, it refuses to operate.

The only other controls I use are the windows common controls , just the slider option, Winsock , which only runs once to check for updates on program load, and a vbprogress bar ocx.

I can't really post the entire program in here, but the actual program has been running for the past few weeks in the editor with no problems. As soon as its compiled it comes up with the strange timer crash problem.

I also tried running the compiled exe on another pc, and had the same problems on that one aswell, so its not local to my machine.  I could send the exe to someone, but its coould be a bit of an epic to register everything related to it.

I'm not a newbie programmer, Though I confess ive not used VB6 for some time now, cant' imagine anything can be wrong as it works fine in the editor just not compiled.. so Im sure this is more than a simple coding problem ?
1
Comment
Question by:exxos_uk
  • 15
  • 9
  • 5
  • +2
32 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 280 total points
ID: 24199534
It sounds like the timer events are retriggering before the code has had chanse to complete so you are ending up with loads and loads of threads running. VB6 is not true multithreading, but can handle many psuedo threads running in a single thread. Can you slow down the timer (maybe 5000ms) and see what happens
0
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 880 total points
ID: 24199635
It sounds like you have ONE textbox that both Timers are writing to.  If so, I could see that you might be running into a timing issue when running the executable where the 1st timer updates the text, but before you can even see the change has been made, the other timer overrides the text.

So I would like to suggest that the way to test the timers is to assign a check box to each one, and on the timer event, have the timer toggle it's check box.  That way, as long as the duration between timer events, is like 1/2 a second or more, the two check boxes should flash on and off to indicate the timers are running.

As for the executable restarting itself, it sounds like you don't have something set up correctly, but at a minimum, I would suggest that on the Form unload event, make sure to disable the timer before unloading the form.  Now this is just a guess... but I think what might be happening is that you unload the form, but the timer is still active.  A timer event occurs, and when the form isn't loaded, the code reloads it so that it can invoke the timer event.

The other thing to watch out for is to make sure you never use the form name in code except to create a new instance of it.  A common mistake I've seen (and even done) with VB is that for every form in your application, VB provides you a "free" instance of that form using the form name.  If you ever use that form name in code, that "free" copy gets invoked rather than the form you think you have loaded.

One way in the debugger to know if you are having a problem properly unloading your forms, run your application in the IDE.  When you click what ever to terminate the application, you should see the "Stop" and "Pause" button deactivate and the "Play" buttom reactivate in the IDE.  If Stop and Pause remain active, then there is something still loaded in memory.
0
 

Author Comment

by:exxos_uk
ID: 24199765
I was thinking along similar lines just! I actually removed one timer and placed 2 seperate sub routines called from a single timer instead (dont know why I didn't just do that in the first place!) the program did run a lot longer before it stopped, so it has improved matters.. though the second time I ran it , it totally crashed and "development enviroment" some debugger ?! kicked in, nothing came up with it though, while on the subject I presume its a part of visual studio, is it possible to turn it off somewhere ?

So the "idea" is that the code is not finishing before the timer is called again.. ok.. i will set the timer to 5000 and report back shortly.
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:exxos_uk
ID: 24199813
HooKooDooKu: - thanks for your pointers! the textbox was just put there to debug only. just so I could see if something was turning off the timers.. its not actually a part of the program, but I can understand your point..

as the the IDE, I did have the problem of when you quit the program the IDE was still in "play mode".. but I used this code and it seems to be ok...

Point taken about the timers being disabled.. though the "reload" problem only happens after the "timer crash" problem.. if you load the app and close it, it does not reload again... but if you leave the program running then it "crashes", then the timer isn't actually running.. in anycase, I will add the lines to disable the timers on unload just to be on the safe side.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
 
Dim Form As Form
   For Each Form In Forms
      Unload Form
      Set Form = Nothing
   Next Form
 
End Sub

Open in new window

0
 

Author Comment

by:exxos_uk
ID: 24200213

Ive set the timer tick to 3,000, so far its cycled 125 times (the program routine that is) before it crashed .. and its not got anywhere near that all day, maximum I had it was 44, with 3-20 cycles the normal crashing point.

I can't imagine why it would crash even with a delay of 3 seconds. All the program does is load a webpage.. and then the timer just checks the page for text, which when found , it saves it to a file. I can't imagine the InStr function taking any amount of time ? Only other operation is file access, which must be the slowest part.. even so the size of the text files in total are only about 10K in size.. can't imagine that taking up 3 seconds of time ?

Is there anyway to work out how long a sub rountine took to complete? May help track down which code is taking the time to run.

Only cure for this that I could think of would be to add a "is_doing_Something" variable..

such as for example...

Private Sub Timer4_Timer()
if is_doing_Something = 1 then exit sub
do_stuff
end sub


Private Sub do_stuff()
is_doing_Something = 1
<<run code>>
is_doing_Something = 0
end sub

The only other events which trigger are the web browser controls.. but all they do is a similar thing to above, but when the browser is busy, it just sets a counter to zero... just helps double check the browser has loaded before the routines check stuff... its only setting a variable so can't imagine that would casue any issues ?

in ancase, if there is some way to time the code then I can look into whats taking so long to happen.. though aso, is my code example the probable only cure to prevent the timer from triggering again before its finished running the code from the previous time?

Have a bad feeling if venture in that method my code is going to get a somewhat messy in working out what code is actually still running or not... I don't suppose there is any VB functions to report which function is actually being looped though at any given time ?
0
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 280 total points
ID: 24200315
It would be better to enable and disable the timers when code that will take time is executing rather that use a clunky boolean.

I normally do the following at the start and end of a procedure to check how long it takes

debug.print "Starting : " & Timer

and

debug.print "Stopping : " & Timer

Timer returns the numbert of milliseconds since midnight so will be accurate enough for this purpose
0
 

Author Comment

by:exxos_uk
ID: 24200441
I will try and setup that to monitor the code time.. may take me a little while as the sub routines exit depending on whats going on at that moment in time...

I can't disable the timer totally.. it would make sense just to load the web page, wait 3 seconds, then run the code and have the timer disable itself again.. but its not that simple as that... for example at random times you have to manually enter information into the website, in which case the timers are just sayt looping and waiting for you to finish, and when you are done, the rountine can carry on automatically... its not always necessary to wait for the page to load fully either... its why the timer loops at say one a second and just keeps checking the page for the data it needs.. once it has it, it can save it to file.. and bascially then the page changes and the loop starts all over again.. I can't think of anyway around that... sometimes adverts come up on the page and it can take 30 seconds for the page to load fully.. but the text is already there so there is no need to wait all that time... its actually an epic in itself so won't go into that now as its not really part of the actual question i asked.

I can't think of any other way to constantly check a page without using a timer, open to suggestions of course, though I think I am back to my problem of the timer running code which it hasn't finished running from the time before yet...

 I am still not 100% sure that is the actual problem, but seems to be pointing towards the right direction for sure. next steps I will have to monitor how long the functions take, then see what the total time is, though can't imagine it taking 3 seconds just for checking text on a page..

By the time I have coded in the start/stop times, ill be half way there to doing the "is_doing_something" method anway. If it still crashes after doing all that then I really will be lost!
0
 
LVL 1

Assisted Solution

by:JosephGermanOcena
JosephGermanOcena earned 80 total points
ID: 24201244
Try inserting a DoEvents inside the timer...

Private Sub Timer4_Timer()
DoEvents
if is_doing_Something = 1 then exit sub
do_stuff
end sub


Private Sub do_stuff()
DoEvents
is_doing_Something = 1
<<run code>>
is_doing_Something = 0
end sub
1
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 880 total points
ID: 24201329
Intuition...
Your program wasn't truly exiting when you would close the form...
After a certain number of iterations, things go haywire...
Timers not behaving like expected...

That sounds like a form might be getting loaded into memory with every timer iteration, but it's not getting unloaded.  After enough iterations you start running out of stack space or resources.  Once the application crashes, VB cleans up all the unloaded forms (sort of has it's own garbage collection that ensures anything allocated gets deallocated to avoid memory leaks).

I could especially see this being the case if the Form has the timer on it, and you don't have just two timers, but lots of timers.

If anything like this is the case, you can likely detect it by adding a Debug.Print message to every form's Load Unload, Initialize, and Terminate event.

As for JosephGermanOcena's suggestion, what that will do is if there are other message in the message que, it will process those messages and then resume your code.  It's a really greaat idea to include some DoEvents when ever you have a process that takes a while.  It allows the UI to continue to react to mouse clicks while the process is running.
0
 

Author Comment

by:exxos_uk
ID: 24202726
I do have DoEvents in anything which can loop in anyway, and even at the start and end of sub routines. I ran into that issue a long time ago where just running the code would in effect lockup the form.

What I have done now, is have the browser events enable the timer, but also sets a counter to zero. The same counter variable is placed in varies sub routines so if anything is going on at all, the counter will be set to zero.. the timer code will only fun when timer count reaches 3 then it runs the code and disables the timer.

When you enable the timer does the timer count reset back to zero, or would it only do that if I disabled and enabled it ?  is there any way to set the actual timer count to zero ? from what I can see you can only set the inverval time and not reset the actual time itself. It would just save me using the "is doing something" variable as I could just reset the timer count back to zero otherwise..

I don't know why I didn't think of that before, there was actually no need to constantly loop the same  code, as it only needs to trigger once after the page changes. So far it has used considerably less CPU time and it operates a lot fast now aswell. Though it crashed totally and windows reported an error with msls31.dll ?

I have some code changes still to make so will report back after more testing.
0
 

Author Comment

by:exxos_uk
ID: 24203106
Seems I am back to square 1 almost here.. The program no longer crashes related to the timer as before, the program just crashes totally now after a few seconds. assuming its events being triggered at the same time, the only events which I can think of doing that are the web browser events.

I had to use WebBrowser1.Silent = True  in there a lot as setting it just once did not block the scripting errors on the webpage. I read something about that somewhere else. Though adding it in the browser events seems to cure that problem.
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
DoEvents
WebBrowser1.Silent = True
DOINGSOMETHING = 1
DoEvents
If stp = 0 And Timer4.Enabled = False Then Timer4.Enabled = True
end sub
 
 
 
Private Sub WebBrowser1_PropertyChange(ByVal szProperty As String)
WebBrowser1.Silent = True
DoEvents
DOINGSOMETHING = 1
DoEvents
If stp = 0 And Timer4.Enabled = False Then Timer4.Enabled = True 
End Sub
 
 
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Silent = True
DoEvents
DOINGSOMETHING = 1
DoEvents
If stp = 0 And Timer4.Enabled = False Then Timer4.Enabled = True 
End Sub

Open in new window

0
 

Author Comment

by:exxos_uk
ID: 24203555
There is another small problem such as... when the timer brances to a sub routine, that subroutine calls another sub routine, so rough idea is  like...


sub timer()
sub1
endsub

sub 1 ()
<run code>>
sub2
<<run code>>
end sub


sub2()
<<code>>
end sub


So does sub1 exit before or after sub2 has been called ?
0
 
LVL 10

Expert Comment

by:peetm
ID: 24205215
Unless sub1 has some sort of 'exit' in its first <run code>, it's impossible.
0
 
LVL 10

Assisted Solution

by:peetm
peetm earned 760 total points
ID: 24205232
It's also not possible for sub1 to be called by sub timer [again] whilst execution of the code doesn't yield - I think there's been some confusion about this in this thread?
0
 

Author Comment

by:exxos_uk
ID: 24205535
peetm:

I am a little confused over what order code is run in.

The way I remember it, is if you called a function again while the function was still operating it would just be placed in a que and wouldn't run until the first loop had finished..

however, the problem was 2 timers I used seemed to be calling 2 sub's at the same time causing the program to crash.

Since then I have placed various checks that the timer will not call the function again until the sub issues a "its done" variable.. this does seem to have cured a lot of the problems..

those I can't exactly get right in my mind about the sub calls...

for example if a timer called a sub every second, and the sub actually took 2 seconds to run.. what happens then ? the timer would try to run the sub again while it hasn't finished running from the previous call yet... as far as im aware it will not call the sub again.. but it has been called so something has to happen at that point ?

I am still having problems with my timer running less than a second at a time.. but it seems to run stable now.. been testing it all afternoon.. soon as you decrease the timer speed to 800mS something happens and it causes crashes... all it does it call the subs faster.. but there shouldn't be any reason for it to crash.. but it does... so I am still trying to find out why the timer is casuing the program to crash.. though it has improved since I started to disable the timer to prevent retriggering of sub's while it could be actually still running the sub's..
0
 
LVL 10

Assisted Solution

by:peetm
peetm earned 760 total points
ID: 24206068
>>for example if a timer called a sub every second, and the sub actually took 2 seconds to run.. what happens then ?

The ans is that the sub would not be re-entered, unless it yielded, i.e., unless it called something like DoEvents - which causes any messages in the app's message-queue to be dispatched - one of those will be a WM_TIMER message, and this is mapped by the VB runtime into a call to your timer sub.

>>what happens then ? the timer would try to run the sub again while it hasn't finished running from the previous call yet... as far as im aware it will not call the sub again.. but it has been called so something has to happen at that point ?

See above.
0
 

Author Comment

by:exxos_uk
ID: 24206181
So really I shouldn't be using doevents in my subs then ?
0
 
LVL 10

Assisted Solution

by:peetm
peetm earned 760 total points
ID: 24206291
>>So really I shouldn't be using doevents in my subs then ?

It's not recommened, and there are some tricks you can do in VB6 to, for example, refresh the UI if it appears to be frozen and won't re-paint.

However, I'm not actually sure that, in VB6, timer subs are re-enterable, i.e., I believe this has been prevented by the VB team.

For example, try this code [which requires a command button and a timer on an otherwise empty form]

See if you can get output that isn't like this:

calls into sub1:1 time. If > 1 then it's been re-entered
calls into sub2:1 time. If > 1 then it's been re-entered
calls into sub1:1 time. If > 1 then it's been re-entered
calls into sub2:1 time. If > 1 then it's been re-entered
calls into sub1:1 time. If > 1 then it's been re-entered
calls into sub2:1 time. If > 1 then it's been re-entered
calls into sub1:1 time. If > 1 then it's been re-entered
calls into sub2:1 time. If > 1 then it's been re-entered
calls into sub1:1 time. If > 1 then it's been re-entered
calls into sub2:1 time. If > 1 then it's been re-entered
calls into sub1:1 time. If > 1 then it's been re-entered


Pressing the command button toggles whether or not DoEvents will be called in sub2.  So, add some code anywhere you like, and see if you can make sub1, sub2 or timer to be re-entered [without calling them direcvtly of course!]


Private Sub Command1_Click()
 
    b = Not b
 
End Sub
 
Private Sub Timer1_Timer()
 
    Static t As Long
 
    sub1
 
    t = t + 1
    
    Debug.Print "calls into sub1:" & t & " time. If > 1 then it's been re-entered"
    
    t = t - 1
 
End Sub
 
Private Sub sub1()
 
    sub2
 
End Sub
 
Private Sub sub2()
 
    Static t As Long
 
    If b Then DoEvents
    
    t = t + 1
    
    Debug.Print "calls into sub2:" & t & " time. If > 1 then it's been re-entered"
    
    t = t - 1
 
End Sub

Open in new window

0
 
LVL 10

Assisted Solution

by:peetm
peetm earned 760 total points
ID: 24206323
And obviously, also set the Timer's Interval to whatever you like.

Setting it to 1 won't result in a tick per ms [actually 18ms or slightly less - more like 15ms], but it'll make it go as fast as possible.
0
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 880 total points
ID: 24206392
Ok, here's a sample application that will show HOW the Timer reacts.  To use it, start a new VB project.  On the Form, place one Timer control and three Command buttons.  The paste the code snippet in the form's code.

The logic is programmed to display a message (along with the time of the message) when the form loads, the form unloads, the timer event starts, and the time event ends.

If you do nothing, the Timer Event will be invoked 5 seconds after the application starts.  The Timer Event will sit in a DoEvents loop for 10 seconds and then terminate the Timer Event.  Five seconds AFTER the Timer Event finishes, the Timer Event will be reinvoked.
If you click Command button 1, the Timer Event will terminate instantly.  Five seconds after you terminate the Timer Event, it will be reinvoked.
If, while waiting for the 5 seconds to elapse before the next Timer Event is invoked, you click Command button 2, the Timer will be disabled and the Timer Event will never get invoked.  If you click the Command button 2 again, the Timer will be enabled and start counting for the 5 seconds before invoking the Timer Event.  If you keep clicking Command button 2 every three seconds, the Timer Event will never be invoked because 5 seconds will never elapse after the last time you toggled the Timer Enabled status.
If while the Timer Event is running you click Command button 3, you will notice that the form disappears instantly in response to the Unload command, however by evidence of the "Play" button and the lack of a message from the "Unload" event, you will see that the Timer Event contiunes to execute and the form doesn't get unloaded until the event completes.  This is likely the cause of your forms reappearing.  You would unload a form, but the form didn't unload, it just became hidden because a Timer Event was still executing.  While executing, something in the code would make the form still loaded in memory visible again.
Option Explicit
Dim m_B As Boolean
Private Sub Form_Load()
    Timer1.Interval = 5000
    Timer1.Enabled = True
    Debug.Print "Start Application " & Format(Now, "hh:mm:ss")
End Sub
Private Sub Timer1_Timer()
Dim StartTime As Date
    Debug.Print "Start Timer " & Format(Now, "hh:mm:ss")
    StartTime = Now
    m_B = True
    Do While m_B
        DoEvents
        If DateDiff("S", StartTime, Now) > 10 Then
            Exit Do
        End If
    Loop
    Debug.Print "End Timer " & Format(Now, "hh:mm:ss")
End Sub
Private Sub Command1_Click()
    m_B = False
End Sub
Private Sub Command2_Click()
    Timer1.Enabled = Not Timer1.Enabled
    Debug.Print "Timer is " & _
                IIf(Timer1.Enabled, "Enabled", "Disabled") & _
                Format(Now, "hh:mm:ss")
End Sub
Private Sub Command3_Click()
    Unload Me
End Sub

Open in new window

0
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 880 total points
ID: 24206457
BTW, what the DoEvents in you subs do is allow the user to interact with the form during the sub.  In the example above, the DoEvents in the Timer Event allows the form to respond to Command Button 2 being clicked while the Timer Event executes.  If you remove the DoEvents from the above example, click events (such as on the Command Buttons) will not execute until the Timer Event finishes execution.  By including the DoEvents, your form continues to respond to other events.
0
 
LVL 16

Assisted Solution

by:HooKooDooKu
HooKooDooKu earned 880 total points
ID: 24206847
BTW2, If you continue playing with this sample application by adding another timer, here is what you will soon discover.
VB is not multithreaded, therefore only one "Event" can execute at a time.  In this case "Event" means the Timer_Event, responding to the command button to call the Command1_Click event, etc.  But these are still Windows applications, as such, activities such as moving the mouse or clicking on controls will still put messages in the Windows Que.
DoEvents causes the execution of a sub/function to pause and go do all the events associated with any messages in the Window's Que.  Once all messages have been processed, then the sub/function resumes.

So when you have two timers and DoEvents within the Timer's Events code, the DoEvents allows other windows messages to be processed (like Command Button Click Events), but is also allows the 2nd timer to take precidence over the 1st timer.

As an example, if Timer1 has an interval of 3 seconds, Timer2 has an interval of 5 seconds, and the Event for both takes 10 seconds to execute and includes DoEvents at least every second, here's how the code will execute: After 3 seconds, Timer1_Event will start execution.  After another 2 seconds, Timer2 will send a message to invoke Timer2_Event.  But Timer2_Event will not start execution until a DoEvents is encountered in Timer1_Event.  When the DoEvents is executed in Timer1_Event, Timer2_Event will begin execution, and Timer1_Event will be "stuck" at the DoEvents until the 10 seconds have elapsed for Timer2_Event to complete execution.

Another way to say this is that in VB, events are done in serial, not parallel.  One event has to complete before another event can begin.  However, DoEvents causes the current event to pause execution and allow all other events to execute.  Once all other events have completed, execution resumes after the DoEvents.  

So by including DoEvents with multiple timers, what is in effect happening is that timers that fire first have their execution interupted by timers that fire later.  Once a secondary timer has been allowed to start execution because of a DoEvents, the 2nd timer event must run to completion before the interupted timer event can resume.
0
 

Author Comment

by:exxos_uk
ID: 24207154
ok I tried both examples and seem to function as you state, tried hard to break it!

my code is using 2 timers 100mS each.. now if you click the command button fast and keep doing it, eventually T will become 2!   it may take a moment of clicking on the button but it can get to 3!

I also removed all the DoEvents and was unable to get it to show a retrigger.. though its hard to say exactly if I am being fooled in just not being shown the number update on screen..

So is DoEvents allowing the sub to run a second time ? or is it just simply just not showing it on the screen  correctly ?
Public t As Integer
 
Private Sub Command1_Click()
    sub2
End Sub
 
 
Private Sub Timer1_Timer()
 
    sub2
 
  
  End Sub
  
Private Sub sub2()
 
    t = t + 1
 
    Debug.Print "calls into sub2:" & t & " time. If > 1 then it's been re-entered"
DoEvents
    t = t - 1
 
End Sub
 
Private Sub Timer2_Timer()
 
sub2
 
End Sub

Open in new window

0
 
LVL 10

Assisted Solution

by:peetm
peetm earned 760 total points
ID: 24207304
Yes, because pressing the button causes a windows message to be put into your application's queue, and VB maps that to a call to the Private Sub Command1_Click() handler.  AND, that message then gets delivered when you call DoEvents.

It'll just take some rapid button pressings before such a thing will be observed, and you happen to have a queued event waiting between inc'ing t and decrementing it again.

0
 

Author Comment

by:exxos_uk
ID: 24207358
right, so next step for me is to remove all my DoEvents and then code should not be able to run twice again. However I will place DoEvents in the timer control so it has some freedom to update the form.. I will see if doing that improves my luck..
0
 
LVL 10

Expert Comment

by:peetm
ID: 24207397
>>right, so next step for me is to remove all my DoEvents and then code should not be able to run twice again.

Correct.


0
 
LVL 10

Expert Comment

by:peetm
ID: 24207410
BTW, to replace them - for testing - write a public sub in a module called myDoEvents that does nothing at all.

Then, do a project wide search & replace, replacing DoEvents with myDoEvents.

That will effectively remove all the DoEvents calls, but, still allow you to easily put them back with another S&R.
0
 

Author Comment

by:exxos_uk
ID: 24207636
what I did was just rem them out .. was 104 Doevents in total..

actually the form has chance to update while the browser control is busy as nothing is running at all for those seconds..

the only doevents I have now are in the form load event, no timers are active then so its not a problem... the only other DoEvents I had to use was in one of the subs which automates a part of the browser control.. it was either skipping it or running to fast to see.. but a DoEvents there seems to work ok.

Also seems to have solve some other odd problems I was having too which were related to the program starting up.. seems to have cured some small errors there too..

Will give it a good testing out and see how things go! if it manages to run for half hour without crashing then that will be a good thing!  Then I will have to re-enable some of the subs I bypassed and hopfully they will function ok now aswell...
0
 

Author Comment

by:exxos_uk
ID: 24209728
Program seems to be running a lot better now, its ran for about a hour and then crashed.. I dont know if I should open up  a new question for this, but I think its when I try to alter the innerhtml of the webrowser while it is still loading the page.

I have a function which just kills the images on the site as it loads aswell as some flash content as it slows the thing down. Also hope it would prevent the images from loading fully as sometimes they can take 30 seconds to load up.. it seems to work, but I think now and then the removal  code must just run while the webrowser is still loading, I tried putting the removal in the webrowser status change event, so it will fire a few times while the page is loading.. though it crashes within seconds..

There is actually 2 things going on removal of a iframe and images.. I will just list the iframe code as the image is just the same pretty much.. I guess its the removal of the iframe which is confusing it.. I will try and confirm that shortly..


Set oImages = WebBrowser1.Document.getElementsByTagName("iframe")      
   For Each oImage In oImages
    Set imageNode = WebBrowser1.Document.createElement("A")           'create a new <a> tag
    imageNode.innerhtml = oImage.innerhtml                            'place the <img> tag with all settings
    Call oImage.replaceNode(imageNode)                                'replace the <img> tag, that is will be <a><img></a>
  Next

Open in new window

0
 
LVL 10

Expert Comment

by:peetm
ID: 24209919
Yes, you should create a new question as it's moving well away from the original "visual basic 6 timer problem".
0
 

Author Closing Comment

by:exxos_uk
ID: 31573016
Fantastic advice thanks everyone!
0
 

Author Comment

by:exxos_uk
ID: 24210124
can someone do a clean up on this and I will open a new question.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

810 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