PC Review


Reply
Thread Tools Rate Thread

Calling a function who's name is trapped in a variable

 
 
GV
Guest
Posts: n/a
 
      7th Oct 2003
Hi,

I am new to VB. I want to be able to call different
function from within another function.

e.g Private Sub FunctionCaller(FunctionName As String)
Call FunctionName(Parameters)
End Sub

Now every time I excute the FunctionCaller it always
return a error message "Compile Error , Execpt Sub,
Function or property"???

I dont know if either I am missing something or I am
totally doing it wrong.

Anyone with any sugessations or any other way of achieving
it?

TIA
GV
 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      7th Oct 2003
GV,
You can use the CallByName function. Or I prefer to use a Delegate:

Something like:

Delegate Sub FunctionName(ByVal a As Integer, ByVal b As String)

Private Sub FunctionCaller(ByVal theFunction As FunctionName)
Dim anInteger As Integer
Dim aString As String

theFunction.Invoke(anInteger, aString)
' or
theFunction(anInteger, aString)

End Function

Private Sub SomeFunction1(ByVal a As Integer, ByVal b As String)
End Sub

Private Sub SomeFunction2(ByVal a As Integer, ByVal b As String)
End Sub

Then when you call the above you use AddressOf

FunctionCaller(AddressOf SomeFunction1)
FunctionCaller(AddressOf SomeFunction2)

Hope this helps
Jay


"GV" <(E-Mail Removed)> wrote in message
news:0d4501c38d03$2dbec080$(E-Mail Removed)...
> Hi,
>
> I am new to VB. I want to be able to call different
> function from within another function.
>
> e.g Private Sub FunctionCaller(FunctionName As String)
> Call FunctionName(Parameters)
> End Sub
>
> Now every time I excute the FunctionCaller it always
> return a error message "Compile Error , Execpt Sub,
> Function or property"???
>
> I dont know if either I am missing something or I am
> totally doing it wrong.
>
> Anyone with any sugessations or any other way of achieving
> it?
>
> TIA
> GV



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Oct 2003
"GV" <(E-Mail Removed)> scripsit:
> I am new to VB. I want to be able to call different
> function from within another function.
>
> e.g Private Sub FunctionCaller(FunctionName As String)
> Call FunctionName(Parameters)
> End Sub
>
> Now every time I excute the FunctionCaller it always
> return a error message "Compile Error , Execpt Sub,
> Function or property"???
>
> I dont know if either I am missing something or I am
> totally doing it wrong.


Have a look at 'CallByName'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method of calling a function where function name is stored in a variable or control Tony Vrolyk Microsoft Access VBA Modules 9 12th Jul 2007 07:20 PM
Method of calling a function where function name is stored in a variable or control Bob Quintal Microsoft Access 2 11th Jul 2007 08:49 PM
calling a sub/function whose name is the value of a variable? H Microsoft VB .NET 5 21st Mar 2007 03:21 PM
Re: Calling record value into function for use as a variable Dirk Goldgar Microsoft Access 2 24th Nov 2003 07:27 PM
Variable changing from value when calling function. Frank Dulk Microsoft Access Form Coding 3 17th Jul 2003 02:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.