Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub: Need urgent help on calling vb function with runtime name

Status
Not open for further replies.

rabindrasaha

Programmer
Jun 4, 2008
1
US
Hi

Problem statement :
I have one MS Excel workbook in which one sheet has a column called "Function Name". That column stores the function names. Those functions vb script functions and are defined in one external .vbs file.

Now I am writing a driver script (.vbs file) which will open that excel sheet and read that column to get function name and then call the correcponding function.

I am having trouble to call a vb function whose name itself is a variable that gets filled in at run time after reading the excel sheet.

Here is the code snippet.
-----------------------------------------------------------
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Project\Company\Controller\input.xls")

intRow = 2
functionName ="test1"

Do Until objExcel.Cells(intRow,1).Value = ""
if ((objExcel.Cells(intRow, 4).Value = "Y") Or (objExcel.Cells(intRow, 4).Value = "Yes")) then
functionName = objExcel.Cells(intRow, 3).Value
Wscript.Echo (functionName)
Call functionName
end if
intRow = intRow + 1
Loop

objExcel.Quit
-----------------------------------------------------------
I know how to call a function defined in some other .vbs file, but problem is how to call a function whose name itself is a variable.

Any help would be highly appreaciated.

Thanks
Rabi
 
[tt]option explicit

function x
wscript.echo "function x is called"
x=100
end function

dim funcname
funcname="x"
dim ret
execute "ret=" & funcname
wscript.echo "ret=" & ret
execute funcname & "()"
execute funcname
[/tt]
 
Replace this:
Call functionName
with this:
Execute functionName

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV is correct, but only as long as you have already read the definition file into memory by reading it's contents into a variable then using Execute or ExecuteGlobal on that variable.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top