问题描述
我正在尝试使用 vbscript 的 Eval(或者我可能需要执行)从 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: est
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 emptyAnd 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
.
You eval'd the literal code pair.key = pair.value
.
That assigns to pair.key
.
您要分配给 pair.key
的 value –如果 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 在循环中将字符串评估为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!