动态变量 [英] Dynamic Variables
问题描述
循环记录集时有没有办法创建动态变量?
例如下面的第一个循环之后我会得到myVarA1和myVarB1,之后是
第二个循环,我会得到myVarA2和myVarB2。
代码************************ ***********
set objRS = GetMyRecordSet()
i = 1
objRS.MoveFirst
Do not not objRS.EOF
" myVarA" &安培; i = objRS(0)
" myVarB" &安培; i = objRS(1)
i = i + 1
objRS.MoveNext()
循环
Is there a way to create dynamic variables when looping through a recordset?
For example below, after the 1st loop I''d have myVarA1 and myVarB1, after
2nd loop, I''d get myVarA2 and myVarB2.
CODE ***********************************
set objRS = GetMyRecordSet()
i=1
objRS.MoveFirst
Do While Not objRS.EOF
"myVarA" & i = objRS(0)
"myVarB" & i = objRS(1)
i = i + 1
objRS.MoveNext()
Loop
推荐答案
scott写道:
有没有办法创建动态变量
有(vbscript Execute语句),但不建议这样做。使用
数组。
循环浏览
记录集时?例如下面,在第一个循环之后我会有myVarA1和
myVarB1,在第二个循环后,我会得到myVarA2和myVarB2。
Is there a way to create dynamic variables
There is (the vbscript Execute statement), but it''s not recommended. Use an
array.
when looping through a
recordset? For example below, after the 1st loop I''d have myVarA1 and
myVarB1, after 2nd loop, I''d get myVarA2 and myVarB2.
使用记录集,GetRows数组似乎非常适合您的目的
Dim arData
如果不是objRS.EOF则arData = objRS.GetRows(,, Array( 0,1))
objRS.Close:设置objRS = Nothing
VarA1对应arData(0,0)
VarB1对应arData(1,0)
VarA2对应arData(0,1)
VarB2对应arData(1,1)
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。我的From
标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。
With a recordset, a GetRows array seems ideal for your purpose
Dim arData
if not objRS.EOF then arData=objRS.GetRows(,,Array(0,1))
objRS.Close: Set objRS = Nothing
VarA1 would correspond to arData(0,0)
VarB1 would correspond to arData(1,0)
VarA2 would correspond to arData(0,1)
VarB2 would correspond to arData(1,1)
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don''t check it very often. You will get a
quicker response by posting to the newsgroup.
谢谢,但我仍然有问题。怎么能动态创建说VarA1,VarA2,VarA3
而无需硬编码?我研究并发现了一种redim方法,
但很困惑。
" Bob Barrows [MVP]" <再****** @ NOyahoo.SPAMcom>在消息中写道
新闻:uD ************** @ TK2MSFTNGP10.phx.gbl ...
Thanks, but I still have a problem. How can create say VarA1, VarA2, VarA3
dynamically without hardcoding them? I researched and found a redim method,
but was confused.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
scott写道:
有没有办法创建动态变量
Is there a way to create dynamic variables
有(vbscript Execute语句),但不建议这样做。使用
数组。
There is (the vbscript Execute statement), but it''s not recommended. Use
an
array.
在循环记录集时?例如下面,在第一个循环之后我会有myVarA1和
myVarB1,在第二个循环之后,我会得到myVarA2和myVarB2。
when looping through a
recordset? For example below, after the 1st loop I''d have myVarA1 and
myVarB1, after 2nd loop, I''d get myVarA2 and myVarB2.
使用记录集,一个GetRows数组看起来很适合你的目的
如果不是objRS.EOF那么昏暗arData
然后arData = objRS.GetRows(,,数组(0,1))
objRS.Close :设置objRS = Nothing
VarA1对应arData(0,0)
VarB1对应arData(1,0)
VarA2对应arData(0,1) )
VarB2对应arData(1,1)
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。我的From
标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将得到更快的回复。
With a recordset, a GetRows array seems ideal for your purpose
Dim arData
if not objRS.EOF then arData=objRS.GetRows(,,Array(0,1))
objRS.Close: Set objRS = Nothing
VarA1 would correspond to arData(0,0)
VarB1 would correspond to arData(1,0)
VarA2 would correspond to arData(0,1)
VarB2 would correspond to arData(1,1)
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don''t check it very often. You will get a
quicker response by posting to the newsgroup.
您不会:使用数组代替动态变量。
而不是VarA1,使用arData(0,0)。
而不是VarB2,使用arData(1,1)
Bob Barrows
scott写道:
You don''t: use the array instead of the dynamic variables.
Instead of VarA1, use arData(0,0).
Instead of VarB2, use arData(1,1)
Bob Barrows
scott wrote:
谢谢,但我还是有问题。怎么能动态创建VarA1,VarA2,
VarA3而不用硬编码呢?我研究并发现了一种
redim方法,但很困惑。
Bob Barrows [MVP]" <再****** @ NOyahoo.SPAMcom>在消息中写道
新闻:uD ************** @ TK2MSFTNGP10.phx.gbl ...
Thanks, but I still have a problem. How can create say VarA1, VarA2,
VarA3 dynamically without hardcoding them? I researched and found a
redim method, but was confused.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
scott写道:
有没有办法创建动态变量
Is there a way to create dynamic variables
有(vbscript Execute语句),但不推荐。
使用
数组。
There is (the vbscript Execute statement), but it''s not recommended.
Use an
array.
在循环播放
记录集时?例如下面,在第一个循环之后,我将拥有myVarA1
和myVarB1,在第二个循环之后,我将获得myVarA2和myVarB2。
when looping through a
recordset? For example below, after the 1st loop I''d have myVarA1
and myVarB1, after 2nd loop, I''d get myVarA2 and myVarB2.
使用记录集,一个GetRows数组看起来很适合你的目的
如果不是objRS.EOF那么昏暗arData
然后arData = objRS.GetRows(,,数组(0,1))
objRS.Close :设置objRS = Nothing
VarA1对应arData(0,0)
VarB1对应arData(1,0)
VarA2对应arData(0,1) )
VarB2对应arData(1,1)
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。我的From
标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。
With a recordset, a GetRows array seems ideal for your purpose
Dim arData
if not objRS.EOF then arData=objRS.GetRows(,,Array(0,1))
objRS.Close: Set objRS = Nothing
VarA1 would correspond to arData(0,0)
VarB1 would correspond to arData(1,0)
VarA2 would correspond to arData(0,1)
VarB2 would correspond to arData(1,1)
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don''t check it very often. You will get
a quicker response by posting to the newsgroup.
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。我的From
标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don''t check it very often. You will get a
quicker response by posting to the newsgroup.
这篇关于动态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!