[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

VB6 independent process

Posted on 2011-02-12
12
Medium Priority
?
355 Views
Last Modified: 2012-05-11
I have a vb6 program that with a timer that does the following:

1)      Queries the database, updates and appends records
2)      Copies images from one server to another

I need step 2 to run independently.  i.e. I do not want step 1 to wait until step 2 completes before running again.  How do I do this in VB6?  I have researched multithreading and am not clear on it or if it is truly possible in VB6?  What about Activex?  I do not have experience with either one.  Can I do this with a timer?
0
Comment
Question by:Delta7428
  • 6
  • 4
  • 2
12 Comments
 
LVL 13

Expert Comment

by:LIONKING
ID: 34878984
The simple solution would be to use two timers, have you tried this?
0
 

Author Comment

by:Delta7428
ID: 34879000
No I haven't tried two timers.  If I started a second timer within the first timer, would they run independetly or would I need to start them independtly when the project loaded or something.
0
 
LVL 13

Expert Comment

by:LIONKING
ID: 34879051
Start them independently one start after the other, and place your code accordingly in each timer. You can also use different delays for each timer if needed.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:Delta7428
ID: 34879053
Thanks.  I'll see how it goes and get back to you.
0
 

Author Comment

by:Delta7428
ID: 34879144
Will the processing speed be the same with both timers running or will it be slowed down?
0
 
LVL 13

Expert Comment

by:LIONKING
ID: 34879909
First I wanna know if it works, because this will not behave like multithreading at all. Did it work?
0
 

Author Comment

by:Delta7428
ID: 34880101
I'm just now working putting the image processing in a separate exe and plan to call one of the exe's from one of the timer events.  The exe willl move a bunch of images and resize, and convert some of them.   I will let you know as soon as I get done and test it if it works.  I need both timer events to run simulataneously...  
0
 
LVL 13

Expert Comment

by:LIONKING
ID: 34880240
Test it because if you want them to run at the exact same time then this approach might not work.
0
 
LVL 5

Accepted Solution

by:
BrianVSoft earned 2000 total points
ID: 34882170
I agree with the two exe idea..
You only need one timer in the main exe - It first Shells the second exe that does the images then calls the sub that updates the database..
The Main exe doesn't wait for the 2nd exe to finish - it drops straight thru to the second task.
So both tasks run together..
It is wise to check for the presence of the small exe before Shelling it again on the next timer event (in case it hasn't finished yet) That's a simple process..
0
 

Author Comment

by:Delta7428
ID: 34882463
BrianVSoft, I'll try it with one timer.  

I tried adding a timer and Shelling the exe from there.  It doesn't work.  The second timer never fires.  Actually I have 3 timers.  The first one only flashes a "tick" label on the screen letting the user know it is running.  The tick timer and the first process timer fires, but the 3rd one does not.

How do I check for the presence of the exe to see if it has finished yet?

0
 
LVL 5

Assisted Solution

by:BrianVSoft
BrianVSoft earned 2000 total points
ID: 34882564
If a Timer never gets to fire, it is usually because the App is performing a long process in a loop that doesn't include a DoEvents.. (Any loop that can process for more than a second or two should include a DoEvents.)

There are two ways to ensure a Shelled App doesn't run twice..
1. In the Apps Form_Load event, test for App.Previous Instance and do an "End" if it is already running..
Eg. If App.PrevInstance Then End
2. Use the FindWindow function to see if it is already running..
You need to know the TITLE of the main form. eg. "MyTitle"
Eg.
  If FindWindow("ThunderRT6FormDC", "MyTitle") = 0 Then..
    Shell the App..
You need to declare this function.. Eg.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
The "ThunderRT6FormDC" is the class name of VB6 type Apps.
0
 

Author Comment

by:Delta7428
ID: 34882616
BrianVSoft, Before I got your post,  I ran it without testing for the presence of the exe first ... the exe that processes the images did not finish.  It probably executed again before it completed.  Is that why?  I'll try your code above and see if that helps.

Also, it ended up I needed 2 exe's.  I'll add it to both.
Private Sub Form_Load()
    mdtTimeNext = Now
    With TimerFlash
        .Interval = 1000 '1 second
        .Enabled = False
    End With
    With TimerFlipControl
        .Interval = 1000 '1 second
        .Enabled = False
    End With
End Sub

Private Sub TimerFlipControl_Timer()
    If Now > mdtTimeNext Then
        '>>Add 5 minutes to current time
        mdtTimeNext = DateAdd("n", 5, Now)
        
        '>process ungrouped orders
        FlipControl
        
         'process grouped orders
        Dim RetVal
        RetVal = Shell("\\mwafs\mis\mis\Projects_Prod\FujiFlip\FujiFlip_Grouped.exe", 1)
        
        '>>Convert and copy images
        RetVal = Shell("\\mwafs\mis\mis\Projects_Prod\FujiFlip\FujiLabelPrint_Images.exe", 1)
    End If
End Sub
Private Sub TimerFlash_Timer()

    With Me.lblMessage
        If .Caption = "" Then
            .Caption = sTimerMessage
        Else
            .Caption = ""
        End If
        
    End With

End Sub

Open in new window

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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

607 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