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

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

问题描述

我正在尝试使用 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 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.

You eval'd the literal code pair.key = pair.value.
That assigns to pair.key.

您要分配给 pair.keyvalue –如果 pair.keymyPath,你想评估 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天全站免登陆