Is it possible to call a function whose name is stored in a string in vbscript?

好久不见. 提交于 2019-11-27 23:21:17
Option Explicit 

function abc(a)
  MsgBox a
End function

dim run : run = "abc ""Hallo"""
execute run

The execute method can do this


Public Function sayhi

msgbox "hi"

end

Dim level0

dim count1
 count1 = DataTable.GetSheet("Action1").GetRowCount
msgBox  count1

For counterVariable = 1 to count1
    functionname = "call " &  DataTable.value("methodnames","Action1")
    execute functionname
    DataTable.GetSheet("Action1").SetCurrentRow(counterVariable)
Next

will call sayhi if its in the datatable.

Use GetRef() to get a 'pointer'/reference to a Sub or Function:

Option Explicit

Sub S1( s )
  WScript.Echo "S1:", GetRef( "F1" )( s )
End Sub

Function F1( s )
  F1 = UCase( s )
End Function

Dim sName : sName     = "S1"
Dim subS1 : Set subS1 = GetRef( sName )

subS1 "abc"

output:

cscript getrefdemo.vbs
S1: ABC
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!