Solved

ActiveX.exe

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now