vbscript在循环中将字符串评估为变量? [英] vbscript Eval a string to a Variable in a loop?

查看:88
本文介绍了vbscript在循环中将字符串评估为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vbscript的Eval(或者可能需要Execute)从ini文件的键名中创建一些变量。该ini文件可以具有无限的未知key = val对。无论如何,我都需要根据键名创建变量。

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 pairs. I need to create a variable based on the key name no matter what.

Ini文件内容:

myPath=c:\test
myExe=myapp.exe
....
xxx=123
yyy=abc

我的代码读取ini并将键和值返回给对象

My code that reads the ini and returns the key and values to an object

我要使用的代码在这里:

The code I am trying to get working is here:

For each pair in objINI
    Eval("pair.key=pair.val")
Next

msgbox myPath
msgbox myExe

但是两个msgbox都显示空的
,是的,我确定pair.key和pair.val具有正确的值。

But both msgbox's are showing empty And yes I am sure pair.key and pair.val have the correct values.

对我所缺少的东西或什至可能的想法?

Thoughts on what I am missing or if this is even possible?

推荐答案

您已将文字代码 pair.key = pair.value

分配给 pair.key

您要分配给 pair.key 。如果 pair.key myPath ,则要评估 myPath = pair.value

您可以通过串联字符串来做到这一点:

You want to assign to the value of pair.key – if pair.key is myPath, you want to eval myPath = pair.value.
You can do that by concatenating strings:

Execute(pair.name + " = pair.value")

这篇关于vbscript在循环中将字符串评估为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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