|
-
Nov 12th, 2002, 10:04 AM
#1
Thread Starter
Frenzied Member
Call a function dynamicly
I want to call a function according the value of a combobox
Let's say my combo is filled with
"code39"
"code41"
"code52"
"code53"
Now i want to execute the function related to the chosen comboitem
Function names are
make_file_code39
make_file_code41
make_file_code52
make_file_code53
tried it with "make_file_" & cmbCode.Value
no luck till now.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 12th, 2002, 10:08 AM
#2
Look into the CallFunctionByName (or CallMEthodByName, or CallByName -- something like that) statement, it should be of help.
-
Nov 12th, 2002, 10:12 AM
#3
Thread Starter
Frenzied Member
The callbymname needs a object where this function resides.
My functions aren't in a class or member of any other object.
Therefore this will not work (tried it already)
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 12th, 2002, 10:21 AM
#4
Banned
You're saying your functions aren't anywhere?
-
Nov 12th, 2002, 10:33 AM
#5
Thread Starter
Frenzied Member
I don't say what you think i am saying
The callbyname function can be used to call functions from objects , objects are classes , a form is also a class.
a simple module isn't a class and therefore can't be used here.
I will have several modules with the code in it to generate files according the type selected in the combo.
I think i will need to use a select case statement to work around this issue;
The whole meaning of calling it dynamicly was , when i add a module to the .mdb (access) i didn't need to add an extra case statement to the code, guess it will be the only way to do it.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 12th, 2002, 10:35 AM
#6
Banned
-
Nov 12th, 2002, 10:40 AM
#7
Junior Member
tried it with "make_file_" & cmbCode.Value
shouldn't it be:
tried it with "make_file_" & cmbCode.Text
My brain hurts from too many loops and arrays so I could be wrong.
-
Nov 12th, 2002, 10:51 AM
#8
Thread Starter
Frenzied Member
Been trying this whole day,
one error i cant get around
Error number 2465
description "Application-defined or object-defined error"
Which object must be specified in it, the functions will be in different code modules ????
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 12th, 2002, 11:08 AM
#9
Thread Starter
Frenzied Member
Got to take some evening course , will check again tommorrow.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 12th, 2002, 11:09 AM
#10
Instead of having these functions in a module, crate a class module with them in instead...this will make things SO much easier 
Woka
-
Nov 12th, 2002, 11:43 AM
#11
swatty: The code that Michael_Kamen pointed out to you is mine. Can I help? What line is giving you that error, and is it from my code or a modificatiion?
-
Nov 12th, 2002, 11:48 AM
#12
The methods are in a module, which can't be passed, as the object, to the CallByName function 
Personally I would add them to a class module, as this would solve loads of problems.
Woka
-
Nov 13th, 2002, 02:39 AM
#13
Thread Starter
Frenzied Member
Marty , the error occures on the line where the call is made.
The code has been modified, but in the other reply you stated it could be called from a code module also.
It doesn't work for me and i think this can't be done that way.
Woka the class isn't an option. I only need to have functions in different modules to be called refering the item chosen in a combo.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 13th, 2002, 04:33 AM
#14
I am at a loss then 
Wonder if you could do something with CopyMemory API...Hmmmm
Woka
-
Nov 13th, 2002, 10:25 AM
#15
Originally posted by swatty
Marty , the error occures on the line where the call is made.
The code has been modified, but in the other reply you stated it could be called from a code module also.
It doesn't work for me and i think this can't be done that way.
Sorry but it looks like you are correct. The called procedures either need to be in the form or a class.
-
Nov 13th, 2002, 10:28 AM
#16
Thread Starter
Frenzied Member
So I may assume your previous answer was not totally correct.
No worries , i'll use a select case then and and a case for each new module created.
Thanks anyway for the reply.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|