Solved

ActiveX.exe

Posted on 2004-08-06
3
391 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

932 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

14 Experts available now in Live!

Get 1:1 Help Now