Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ActiveX.exe

Posted on 2004-08-06
3
Medium Priority
?
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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 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…
Suggested Courses

721 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