Solved

ActiveX.exe

Posted on 2004-08-06
3
392 Views
Last Modified: 2010-10-05
I've created a activeX.exe project as per this website:
http://kandkconsulting.tripod.com/VB/Tutorials/activex_exe_tutorial.htm (see code below)

How would I modify this project so that I can execute 10 simultaneous instances of the "MakeMeProcess" routine?  I would like it to dynamically created the objects and when the process is finished return the result.

I can do it by hardcoding separate events and separate objects, but it’s ugly and not dynamic.  

e.g:
Set MyEXE1 = New MyFirstEXE.clsMain
Set MyEXE2 = New MyFirstEXE.clsMain
Set MyEXE3 = New MyFirstEXE.clsMain

Private Sub MyEXE1_Finished(Message As String)
MsgBox Message
End Sub
Private Sub MyEXE2_Finished(Message As String)
MsgBox Message
End Sub
Private Sub MyEXE3_Finished(Message As String)
MsgBox Message
End Sub

I would ultimately change the code for my purposes and have it dynamically create as MakeMeProcess instances that I would need.

'Here’s the ActiveX Client Code as per the above URL:

Option Explicit

Private WithEvents MyEXE    As MyFirstEXE.clsMain


Private Sub Command1_Click()
    MyEXE.MakeMeProcess (1000) ' Make the ActiveX simulate processing by doing 1000 loops
End Sub

Private Sub Form_Load()

Set MyEXE = New MyFirstEXE.clsMain

End Sub

Private Sub Form_Unload(Cancel As Integer)
Set MyEXE = Nothing

End Sub

Private Sub MyEXE_Finished(Message As String)
MsgBox Message
End Sub

'Here the ActiveX Server code as per the above URL:
Option Explicit
'********************************************************************************
'*  Class Name:     clsMain                                                     *
'*  Date:           Tuesday, January 29, 2002                                   *
'*  Author:         The VB Guru                                                 *
'*  Compiler:       Microsoft Visual Basic 6.00 sp4                             *
'*  Synop:          This is a demo to show how to create and use an ActiveX EXE *
'*                                                                              *
'********************************************************************************

Private WithEvents ProcTimer    As TimerLite.clsTimerLite

Public Event Finished(Message As String)

Private lLoops                  As Long

Public Sub MakeMeProcess(ByVal NumberOfLoops As Long)

'********************************************************************************
'*  Sub Name:  MakeMeProcess                                                    *
'*  Date:      Tuesday, January 29, 2002                                        *
'*  Author:    Kevin Henderson                                                  *
'*  Compiler:  Microsoft Visual Basic 6.00                                      *
'*  Args:                                                                       *
'*             Long:  NumberOfLoops --   This is the number of seconds you want *
'*                                       The EXE to process on it's own.        *
'*  Synop:     For demonstration purposes, we are going to simulate this EXE  *
'*             Running on it's own, this will be done by way of a timer.        *
'*             We also have to prevent the VB thread from yielding, so...as I   *
'*             Said in the tutorial, we need to create a timer here too so the  *
'*             Sub will return right away and the timer will call the function  *
'*             we want.                                                         *
'*                                                                              *
'********************************************************************************

Set ProcTimer = CreateObject("TimerLite.clsTimerLite")

With ProcTimer
    .Interval = 500
    .Enabled = True
End With

lLoops = NumberOfLoops

End Sub
Private Sub IntMakeMeProcess(ByVal NumberOfLoops As Long)

'********************************************************************************
'*  Sub Name:  IntMakeMeProcess                                                 *
'*  Date:      Tuesday, January 29, 2002                                        *
'*  Author:    The VB Guru                                                      *
'*  Compiler:  Microsoft Visual Basic 6.00                                      *
'*  Args:                                                                       *
'*             Long:  NumberOfLoops --   This is the number of seconds you want *
'*                                       The EXE to process on it's own.        *
'*  Synop:     As you can see, this sub is Private and can only be called from  *
'*             within this class.  It is only called when the ProcTimer fires   *
'*             And passes the same value as MakeMeProcess(). This allows the    *
'*             VB thread to continue processing and the thread in this class to *
'*             Process at the same time.                                        *
'*                                                                              *
'********************************************************************************

Dim counter As Long

' do some processing, in this case we are just going to loop to simulate some lengthy process.

For counter = 0 To NumberOfLoops
    DoEvents
Next

RaiseEvent Finished("All done") ' Let the client know we are done
End Sub



Private Sub ProcTimer_Timer()

With ProcTimer
    .Interval = 0
    .Enabled = False
End With

IntMakeMeProcess lLoops     ' When the timer fires, call the internal function that the user thought they were calling

Set ProcTimer = Nothing

End Sub

Private Sub Class_Terminate()
    Set ProcTimer = Nothing ' Clean up time
End Sub



0
Comment
Question by:Pber
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
ID: 11738575
Can you just create a class

ie

In your project, all a class with name class1


in class1

private withevent myexe as MyFirstEXE.clsmain

Private Sub Class_Initialize()
Set MyEXE = New MyFirstEXE.clsMain

End Sub

Private Sub MyEXE_Finished(Message As String)
MsgBox Message
End Sub


In your form


dim cls1(10) as class1


for i = 1 to 10
set cls1(i) = new class1
next



etc
0
 
LVL 26

Author Comment

by:Pber
ID: 11738892
thanks for the info...

How would I go about calling the MakeMeProcess routine?
0
 
LVL 26

Author Comment

by:Pber
ID: 11741295
Never Mind, I just had to make the class object public....
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

815 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

11 Experts available now in Live!

Get 1:1 Help Now