×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

There is a "Call" function in VBScript, but the function name could not be a variable.

Visual Basic Scripting Edition Language Reference

--------------------------------------------------------------------------------

Call Statement
Transfers control to a Sub or Function procedure.

[Call] name [argumentlist]

Arguments
Call

Optional keyword. If specified, you must enclose argumentlist in parentheses. For example:

Call MyProc(0)

name

Required. Name of the procedure to call.

argumentlist

Optional. Comma-delimited list of variables, arrays, or expressions to pass to the procedure.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / In VBScript, can I call Sub in an array? How? -- Urgently need help
    For example, I have several Subs such as
    Sub MsoffXP
    .......
    End Sub

    Sub lotus123
    ......
    End Sub

    Sub Notes
    ...
    End Sub

    I want to define an array to call these Subs
    Array[1] --> Msoffxp
    Array[2] -->Lotus123
    Array[3] --> Notes

    But in VBScript, there's no Call command, how can I call sub using the variable?

    Thanks for your help!
    • there's no Call command---------WRONG
      • Thanks for your reply. ..... But how to resolve my following problem? thanks
        I have several Subs such as
        Sub MsoffXP (parameter1)
        .......
        End Sub

        Sub lotus123 (parameter2)
        ......
        End Sub

        Sub Notes (parameter3)
        ...
        End Sub

        I want to define an array to call these Subs
        Array[1] --> Msoffxp
        Array[2] -->Lotus123
        Array[3] --> Notes

        how can I call Subs?

        Thanks for your help!
        • here
          for x=0 to (array.length-1)
          select case x
          case 0
          call ...
          case 1
          call...
          end select
          Next
        • 俺帮你搞定,请俺喝啤酒吗?一瓶
          aFunc = array("Func1","Func2")

          parm="hello"
          sFunc = aFunc(0) + "(""" & parm & """)"
          call eval(sFunc)

          function Func1(sParm)
          '// code for this function goes here.
          end function
    • There is a "Call" function in VBScript, but the function name could not be a variable.
      Visual Basic Scripting Edition Language Reference

      --------------------------------------------------------------------------------

      Call Statement
      Transfers control to a Sub or Function procedure.

      [Call] name [argumentlist]

      Arguments
      Call

      Optional keyword. If specified, you must enclose argumentlist in parentheses. For example:

      Call MyProc(0)

      name

      Required. Name of the procedure to call.

      argumentlist

      Optional. Comma-delimited list of variables, arrays, or expressions to pass to the procedure.
    • 能改成用JSCRIPT/JAVASCRIPT吗? 我肯定VBSCRIPT是可以实现的, 但语法忘了. JSCRIPT见内, IE运行通过
      var s=new Array

      function A(){alert('abc')}
      function B(){}
      function C(){}

      s[0]=A
      s[1]=B
      s[2]=C

      i=0
      s[i]();
    • Thank you all. But I need to use VBScript. Actually, I can use another way to call this functions one by one. but .......
      本文发表在 rolia.net 枫下论坛my co-worker wanted me to find a easy way to do this. I thought of the array method, original code is as following....
      "
      Sub fin_sbarep11(strAppID)
      Dim strAppDir, strSetup, strSecGrp, strGrpDesc, strProgDir
      '***********************************
      '* SBA Reporting Corporations V1.1*
      '***********************************
      strAppDir = strLobDir & "\Common\" & strAppID
      strSetup = strAppDir & "\sbarep11.msi allusers=2 /qb-"
      AppInstall strAppID, strSetup, strAppDir & "\" & strAppID & ".reg"
      strProgDir = vbQt & "c:\program files\SBA Electronic Reporting Corporations" & vbQt
      strShCutDir = vbQt & "C:\Documents and Settings\All Users\Start Menu\Programs\SBA Electronic Reporting (C)" & vbQt
      strSecGrp = "AppSBARep"
      strGrpDesc = "SBA Reporting Corporations Users"
      CreateLocalGroup strSecGrp, strGrpDesc
      Global2Local strDomain, strSecGrp, strSecGrp
      objWshShell.Run iGrant & " -hideprop protect " & strProgDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":Modify,Modify,Modify " & strProgDir, 1, TRUE
      objWshShell.Run irevoke & " -r -rd -ru -hideprop users:cteau,cteau,cteau " & strProgDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop protect " & strShCutDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":cteau,cteau,cteau " & strShCutDir, 1, TRUE
      objWshShell.Run irevoke & " -r -hideprop users:cau,cau,cau " & strShCutDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop users:TE " & strShCutDir, 1, TRUE
      End Sub

      Sub fin_txbro10(strAppID)
      Dim strAppDir, strSetup, strSecGrp, strGrpDesc, strProgDir
      '********************************
      '* Transaction History Browser *
      '********************************
      strAppDir = strLobDir & "\Common\" & strAppID
      strSetup = strAppDir & "\setup /s"
      AppInstall strAppID, strSetup, strAppDir & "\" & strAppID & ".reg"
      AddPath "c:\Progra~1\pb6dll\"
      strProgDir1 = vbQt & "C:\Program Files\TX_BROW" & vbQt
      strProgDir2 = vbQt & "C:\Program Files\pb6dll" & vbQt
      strShCutDir = vbQt & "C:\Documents and Settings\All Users\Start Menu\Programs\Browser" & vbQt
      strSecGrp = "AppTxBro11"
      strGrpDesc = "Transaction History Browser Users"
      CreateLocalGroup strSecGrp, strGrpDesc
      Global2Local strDomain, strSecGrp, strSecGrp
      objWshShell.Run iGrant & " -hideprop protect " & strProgDir1, 1, TRUE
      objWshShell.Run iGrant & " -hideprop protect " & strProgDir2, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":Modify,Modify,Modify " & strProgDir1, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":Modify,Modify,Modify " & strProgDir2, 1, TRUE
      objWshShell.Run irevoke & " -r -rd -ru -hideprop users:cteau,cteau,cteau " & strProgDir1, 1, TRUE
      objWshShell.Run irevoke & " -r -rd -ru -hideprop users:cteau,cteau,cteau " & strProgDir2, 1, TRUE
      objWshShell.Run iGrant & " -hideprop protect " & strShCutDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":cteau,cteau,cteau " & strShCutDir, 1, TRUE
      objWshShell.Run irevoke & " -r -hideprop users:cau,cau,cau " & strShCutDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop users:TE " & strShCutDir, 1, TRUE
      End Sub

      Sub fin_pfsct12(strAppID)
      Dim strAppDir, strSetup, strSecGrp, strGrpDesc, strProgDir
      '**********************
      '* Comshare Decision *
      '**********************
      strAppDir = strLobDir & "\Common\" & strAppID
      strSetup = strAppDir & "\pfsct12.msi allusers=2 /qb-"
      AppInstall strAppID, strSetup, strAppDir & "\" & strAppID & ".reg"
      AddPath "c:\Program Files\ComShare\Shared~1;"
      strProgDir1 = vbQt & "c:\program files\comshare" & vbQt
      strProgDir2 = vbQt & "c:\program files\decision" & vbQt
      strShCutDir = vbQt & "C:\Documents and Settings\All Users\Start Menu\Programs\Decision" & vbQt
      strSecGrp = "AppDecision"
      strGrpDesc = "Comshare Decision Users"
      CreateLocalGroup strSecGrp, strGrpDesc
      Global2Local strDomain, strSecGrp, strSecGrp
      objWshShell.Run iGrant & " -hideprop protect " & strProgDir1, 1, TRUE
      objWshShell.Run iGrant & " -hideprop protect " & strProgDir2, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":Modify,Modify,Modify " & strProgDir1, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":Modify,Modify,Modify " & strProgDir2, 1, TRUE
      objWshShell.Run irevoke & " -r -rd -ru -hideprop users:cteau,cteau,cteau " & strProgDir1, 1, TRUE
      objWshShell.Run irevoke & " -r -rd -ru -hideprop users:cteau,cteau,cteau " & strProgDir2, 1, TRUE
      objWshShell.Run iGrant & " -hideprop protect " & strShCutDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop " & strSecGrp & ":cteau,cteau,cteau " & strShCutDir, 1, TRUE
      objWshShell.Run irevoke & " -r -hideprop users:cau,cau,cau " & strShCutDir, 1, TRUE
      objWshShell.Run iGrant & " -hideprop users:TE " & strShCutDir, 1, TRUE
      End Sub



      strAppID = "sbarep11"
      strAppDesc = objWshShell.RegRead("HKLM\Software\COE\" & strAppID)
      If Err Then
      fin_sbarep11 strAppID
      End If
      Err.Clear

      strAppID = "txbro10"
      strAppDesc = objWshShell.RegRead("HKLM\Software\COE\" & strAppID)
      If Err Then
      fin_txbro10 strAppID
      End If
      Err.Clear

      strAppID = "pfsct12"
      strAppDesc = objWshShell.RegRead("HKLM\Software\COE\" & strAppID)
      If Err Then
      fin_pfsct12 strAppID
      End If
      Err.Clear
      "
      This is a part of the whole script , Do you have any solutions to make it easier read and coded by array.

      Thanks更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • VB solution:
      dim arry

      arry=Array()

      sub A()
      msgbox("hello A")
      end sub

      sub B()
      msgbox("hello B")
      end sub

      set arry(0)=GetRef("A")

      i=0
      arry(i)()