vbscript Eval a string to a Variable in a loop?

前端 未结 3 1805
梦如初夏
梦如初夏 2020-12-22 01:33

I am trying to use vbscript\'s Eval (or maybe I need Execute) to create some variables from the key names from an ini file. The ini file can have unlimited unknown key=val p

3条回答
  •  旧时难觅i
    2020-12-22 01:44

    You need to Execute (an assign statement), not to Eval(uate a boolean expression):

    >> n = "Name"
    >> v = "Value"
    >> WScript.Echo TypeName(Eval("n=v"))
    >>
    Boolean
    >> Execute "n=v"
    >> WScript.Echo n
    >>
    Value
    >>
    

    From the docs:

    In VBScript, x = y can be interpreted two ways. The first is as an assignment statement, where the value of y is assigned to x. The second interpretation is as an expression that tests if x and y have the same value. If they do, result is True; if they are not, result is False. The Execute statement always uses the first interpretation, whereas the Eval method always uses the second.

    (This does not mean you should do such things; neither at home, nor at work)

提交回复
热议问题