本文介绍了动态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

循环记录集时有没有办法创建动态变量?

例如下面的第一个循环之后我会得到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

推荐答案




使用记录集,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.




有(vbscript Execute语句),但不建议这样做。使用
数组。



There is (the vbscript Execute statement), but it''s not recommended. Use
an
array.



使用记录集,一个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.





有(vbscript Execute语句),但不推荐。
使用
数组。



There is (the vbscript Execute statement), but it''s not recommended.
Use an
array.



使用记录集,一个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.


这篇关于动态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 18:28