473,473 Members | 4,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

calling a sub/function whose name is the value of a variable?

H
dim subName = "GetTable" & strCtr & "()"

I want to now call the GetTable1() sub or GetTable2() sub, depending
on
the value of strCtr.

How can I call the function whose name is in the variable subName?
thanks...

Mar 20 '07 #1
5 1410
If subName = "GetTable1()" then
Call GetTable1()
elseif SubName = "GetTable2()" then
Call GetTable2()
Endif

But why bother with SubName? Just use strCtr instead of it.

Bill

On Mar 20, 1:54 pm, "H" <halukdot...@gmail.comwrote:
dim subName = "GetTable" & strCtr & "()"

I want to now call the GetTable1() sub or GetTable2() sub, depending
on
the value of strCtr.

How can I call the function whose name is in the variable subName?

thanks...

Mar 20 '07 #2
H
thanks for the reply, however, I was in search of a way to call the
actual value of the variable

for example...

public sub DynamicCaller( ByVal strCtr as Integer)
Dim subName = "GetTable" & strCtr & "()"
'strCtr can be between 1 and 9

'here, need to call the function name of whatever is in subName
magicMethod(subName) 'doesn't necessarily have to be a method
name, should be anything that literally runs the value of the variable
' this magic method will either call GetTable1() or GetTable2() or
etc....

End Sub

billsahi...@yahoo.com wrote:
If subName = "GetTable1()" then
Call GetTable1()
elseif SubName = "GetTable2()" then
Call GetTable2()
Endif

But why bother with SubName? Just use strCtr instead of it.

Bill

On Mar 20, 1:54 pm, "H" <halukdot...@gmail.comwrote:
dim subName = "GetTable" & strCtr & "()"

I want to now call the GetTable1() sub or GetTable2() sub, depending
on
the value of strCtr.

How can I call the function whose name is in the variable subName?

thanks...
Mar 20 '07 #3
H,

If you can live with its limitations, CallByName is the easiest way to do
this in VB.

Kerry Moorman
"H" wrote:
dim subName = "GetTable" & strCtr & "()"

I want to now call the GetTable1() sub or GetTable2() sub, depending
on
the value of strCtr.

How can I call the function whose name is in the variable subName?
thanks...

Mar 20 '07 #4
Hi H,

Why making it yourself difficult.
This can be typed in 10 minutes.

GetTable1
GetTable2
GetTable3
....
GetTable9

Cor
"H" <ha*********@gmail.comschreef in bericht
news:11*********************@p15g2000hsd.googlegro ups.com...
thanks for the reply, however, I was in search of a way to call the
actual value of the variable

for example...

public sub DynamicCaller( ByVal strCtr as Integer)
Dim subName = "GetTable" & strCtr & "()"
'strCtr can be between 1 and 9

'here, need to call the function name of whatever is in subName
magicMethod(subName) 'doesn't necessarily have to be a method
name, should be anything that literally runs the value of the variable
' this magic method will either call GetTable1() or GetTable2() or
etc....

End Sub

billsahi...@yahoo.com wrote:
>If subName = "GetTable1()" then
Call GetTable1()
elseif SubName = "GetTable2()" then
Call GetTable2()
Endif

But why bother with SubName? Just use strCtr instead of it.

Bill

On Mar 20, 1:54 pm, "H" <halukdot...@gmail.comwrote:
dim subName = "GetTable" & strCtr & "()"

I want to now call the GetTable1() sub or GetTable2() sub, depending
on
the value of strCtr.

How can I call the function whose name is in the variable subName?

thanks...

Mar 21 '07 #5
On Mar 20, 3:54 pm, "H" <halukdot...@gmail.comwrote:
dim subName = "GetTable" & strCtr & "()"

I want to now call the GetTable1() sub or GetTable2() sub, depending
on
the value of strCtr.

How can I call the function whose name is in the variable subName?

thanks...
Here's an example of doing a late bound call to Console.WriteLine.

Public Sub Example()
Dim methodName As String = "WriteLine"
Dim methodArgs() As Type = { }
Dim method As MethodInfo = GetType(Console).GetMethod(methodName,
methodArgs)
method.Invoke(Nothing, Nothing)
End Sub
Mar 21 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
8
by: guillaume | last post by:
hello from france, I want to edit a list of customers dynamically and each row contains an input text with the name of customer and link to update the name the link calls the javascript ...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
10
by: headware | last post by:
I know that you can call the method of one from from inside another form by doing something like this Forms("MyForm").MyFunction(12, 34) However, you have to know that MyForm has a function...
5
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
3
by: NightCrawler | last post by:
Hi can i call a constructor of a class, if the name is stored in a CString Object e.g. class CBaseClass { int x; };
4
by: florian.loitsch | last post by:
I wondered what should be the result of the following code: === function f() { x = false; function x() {}; alert(x); } === According to Ecmascript-spec we have the following rules: 10.1.3:...
6
by: Sagari | last post by:
Greetings, Can someone suggest an efficient way of calling method whose name is passed in a variable? Given something like: class X: #... def a(self):
0
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.