Solved

Class Procedure Question (in an ActiveX EXE)

Posted on 2000-04-10
5
136 Views
Last Modified: 2010-05-02
I have an ActiveX EXE class called clsSimulation which has the basic form:

Public Sub StartSimulation(args ...)

    "Show form code"
    "call dll procedure"

End Sub

Public Sub EndSimulation()

    "Unload form code"

End Sub

My question: why can I only pass one argument to the StartSimulation procedure? Ideally, I would like to pass four arguments as:

x.StartSimulation(arg1,arg2,arg3,arg4)

But VB will not let me ... perhaps their is some basic misunderstanding I have about classes.

Thanks for assistance.
--
Fred Phelan
frederick.phelan@nist.gov
0
Comment
Question by:phalanx777
5 Comments
 

Expert Comment

by:patm_EE
ID: 2701863
I just tested this..

Assuming this:
The Public Sub StartSimulation is a method of your class defined as folows:

Public Sub StartSimulation (str1 as string, str2 as string, str3 as string, str4 as string)

' Do some Stuff

End Sub

You will be REQUIRED to pass 4 arguments...

Maybe I'm missing something...
0
 

Author Comment

by:phalanx777
ID: 2702063
Ok, I did forget to mention that they are not all strings! I am trying to mix a variety of variables in the call to StartSimulation. But it does not really matter, take this specific example:

Public Sub StartSimulation (test_long as Long, test_string as String)

     "code to manipulate test_long and test_string"

End Sub

Then, remember, this is an ActiveX exe. Go to the project you want to us the AXE in ... check it in under references. Then try the code (say in a button callback)

Private Sub Command1_Click()
    Dim test_long As Long
    Dim test_string As String
    test_long = 999
    test_string = "The test string!"
    Set x = New axe.Class1
    x.StartSimulation (test_long,test_string)
End Sub

You will see that the x.StartSimulation is all in red ... indicating an error and the error message is:

Compile error:

Expected: =


Hopefully that clears things up!

Fred

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2703036
This Procedure declaration requires 1 parameter, with the next three being optional. If Nothing is passed via parameters 2,3+4 the Default Value "None" is placed into them. An Example of useage would be:

call StartSimulation ("X",,"Z")

which would give the result..

varArg1 = "X"
varArg2 = "None"
varArg3 = "Z"
varArg4 = "None"

in the subroutine.

------------------------------------
Public Sub StartSimulation _
(Byval varArg1 as Variant, _
Optional Byval varArg2 as Variant = "None", _
Optional Byval varArg3 as Variant = "None", _
Optional Byval varArg3 as Variant = "None")








   
0
 
LVL 3

Accepted Solution

by:
Gordonp earned 50 total points
ID: 2703128
phalanx777>
ITs a simple thing really

replace

x.StartSimulation (test_long,test_string)

with

x.StartSimulation test_long,test_string

placing ( ) round your parameters is only for when you return a value.

for some reason VB lets you away with it if you only have one parameter.

Call x.StartSimulation (test_long,test_string)

also works. But I dont like it. Try it and see.

Hope this helps

Gordon

0
 

Author Comment

by:phalanx777
ID: 2704251
You hit the nail on the head! Problem solved!

Thanks, Fred


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

831 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