Solved

ActiveX.exe

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

821 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