是否可以调用名称存储在 vbscript 中的字符串中的函数? [英] Is it possible to call a function whose name is stored in a string in vbscript?

查看:42
本文介绍了是否可以调用名称存储在 vbscript 中的字符串中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这样在qtp中编写脚本

i am trying to write a script in qtp like this

Public Function sayhi

msgbox "hi"

end

Dim level0

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

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

假设函数名将有一个值说sayhi".我可以使用该值来调用函数吗?就像我在代码调用函数名"中所做的那样.

assume functionname is going to have a value say "sayhi". Can i use that value to call the function ? like i did in the code "call functionname".

我知道它不起作用,但如何进行这样的调用?

I know it is not working but how to do such call ?

推荐答案

Option Explicit 

function abc(a)
  MsgBox a
End function

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

execute 方法可以做到这一点

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

如果它在数据表中,将调用 sayhi.

will call sayhi if its in the datatable.

这篇关于是否可以调用名称存储在 vbscript 中的字符串中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆