我有这些变量
STATE_Newverifdetaillibelle_208="test"
STATE_Newverifdetaillibelle_209=""
STATE_Newverifdetaillibelle_210=""
STATE_Newverifdetaillibelle_211=""
STATE_Newverifdetaillibelle_212=""
STATE_Newverifdetaillibelle_213=""
STATE_Newverifdetaillibelle_214=""
STATE_verifmoduleid="208, 209, 210, 211, 212, 213, 214"
所以我想根据列表/数组获取不为空的变量
在我的示例中,STATE_verifmoduleid
包含以下内容:
STATE_verifmoduleid="208, 209, 210, 211, 212, 213, 214"
所以基本上,我应该只抓STATE_Newverifdetaillibelle_208="test"
,因为它不为空。
我编写了这段代码,但是没有返回变量"TEST"
中包含的值STATE_Newverifdetaillibelle_208="test"
Dim STATE_Newverifdetaillibelle_(1000)
Dim verifmoduleid
'Here the code of the form/request.form, bla bla bla which is working ...
Dim CheckVerifyModulesIDs,CheckVerifyModulesID, Citems
CheckVerifyModulesIDs = replace(STATE_verifmoduleid," ","")
CheckVerifyModulesID = Split(CheckVerifyModulesIDs,",")
For each Citems in CheckVerifyModulesID
if (STATE_Newverifdetaillibelle_(Citems)) <> "" then
response.write (STATE_Newverifdetaillibelle_(Citems)) & "<br>"
end if
next
我该如何解决?
答案 0 :(得分:0)
所有变量STATE_Newverifdetaillibelle_*
分别声明,因此您需要动态地将每个变量名构建为字符串,并将该字符串作为表达式求值。
STATE_Newverifdetaillibelle_208 = "test"
STATE_Newverifdetaillibelle_209 = ""
STATE_Newverifdetaillibelle_210 = ""
STATE_Newverifdetaillibelle_211 = ""
STATE_Newverifdetaillibelle_212 = ""
STATE_Newverifdetaillibelle_213 = ""
STATE_Newverifdetaillibelle_214 = ""
STATE_verifmoduleid = "208, 209, 210, 211, 212, 213, 214"
' Here the code of the form/request.form, bla bla bla which is working ...
ids = Split(Replace(STATE_verifmoduleid," ",""),",")
For Each id in ids
v = Eval("STATE_Newverifdetaillibelle_" & id)
If v <> "" then
Response.Write v & "<br>"
End If
Next
另一种方法是将所有值放入数组或字典中,因此无需使用Eval
。