通过串联VBS中的其他两个变量名称来定义新变量 [英] Define a new variable by concatenation of two other variable names in VBS

查看:187
本文介绍了通过串联VBS中的其他两个变量名称来定义新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我两周前正在编写一个长脚本,现在由于脚本的编写方式,我需要通过串联两个现有变量名来定义变量名。我不想连接它们的值,而是连接变量本身以创建新变量。
听起来可能很可笑,但是鉴于这种情况,我别无选择。

I am writing a long script for two weeks ago and now due to the way whose it's written, I need to define a variable name by concatenation of two existing variable names. I don't want to concatenate their values but the variables themselves in order to make a new variable. That may sound ridicule, but given the situation, I have no other choice.

Is it possible? 

感谢您的理解。

推荐答案

VBScript不支持自省,因此您无法从脚本内部动态解析变量名。但是,可能有一种可行的方法。如果不是使用变量 a b ,而是使用键为 a的字典 b ,您可以将这些键名连接起来以生成新的键 ab

VBScript doesn't support introspection, so you can't dynamically resolve variable names from within the script. However, there might be a possible way to go about. If instead of variables a and b you use a dictionary with keys "a" and "b" you could concatenate those key names to produce a new key "ab":

Set d = CreateObject("Scripting.Dictionary")
d.Add "a", 23
d.Add "b", 42

newkey = ""
For Each key In d.Keys
  newkey = newkey & key
Next

d.Add newkey, 2342

但是,如果您描述的是您要解决的实际问题而不是您认为的解决方案,则可能会得到更好的答案。

However, you might be able to get a better answer if you described the actual problem you're trying to solve instead of what you perceive as the solution.

这篇关于通过串联VBS中的其他两个变量名称来定义新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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