Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a function with function name reference to a string value in VB

Tags:

vb6

I have this algorithm that I want to implement on VB6.

Sub Main()
dim stringVal1 as string, stringVal2 as string
dim getOne as boolean

stringVal1 = "FunctOne"
stringVal2 = "FunctTwo"

if getOne then
    'Call Function with function name assigned to stringVal1 ... how to call the function here?**
else
    'Call Function with function name assigned to stringVal1 ... how to call the function here?**
end if

End Sub


Function FunctOne()
   Msgbox "I'm function one"
End Function

Function FunctTwo()
   Msgbox "I'm function two"
End Function

Can this be done in VB6?

like image 337
Kratz Avatar asked Apr 14 '26 00:04

Kratz


1 Answers

Generally, such code patterns point to errors in your software design.

In the rare cases where this is really needed, CallByName accomplishes this.

Example:

Call CallByName(Me, "NameOfFunction", vbMethod, arguments)
like image 198
Konrad Rudolph Avatar answered Apr 19 '26 00:04

Konrad Rudolph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!