Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: defining multiple variables in a loop


Message #1 by "Spencer Saunders" <ssaunders@i...> on Thu, 9 Aug 2001 01:06:49 -0400

I am having a problem with getting a number of variables set in a loop. 

I keep getting a syntax error and I can't figure out how to fix it.



code.



varmaxcount=3Dcategorycheck.recordcount

i=3D1

Do While NOT i > varmaxcount

varcat&i=3Dcategorycheck("category")

categorycheck.movenext

i =3D i+1

Loop



But I am getting a syntax error on the line with 

"varcat&i=3Dcategorycheck("category")".

What is the syntax to append a numeric value onto the end of a variable 

name???

in the end I would like a list of variables that look lie this

var1=3D"articles"

var2=3D"general"

etc...





TIA



spence



=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

=3D=3D=3D=3D=3D=3D::



Spencer Saunders

www.spencersaunders.com

ssaunders@i...



Message #2 by =?iso-8859-1?Q?R=E9my_MARICIC?= <remind@n...> on Thu, 9 Aug 2001 12:25:11 +0200
It's not possible to create a name of a variable "on the fly"



You should use a collection, e.g:



Set Col = Server.CreateObject("Scripting.Dictionary")



varmaxcount = 3Dcategorycheck.recordcount

i = 3D1

Do While NOT i > varmaxcount

	Col.Add "varcat" +Cstr(i), Cstr(3Dcategorycheck("category"))

	categorycheck.movenext

	i =3D i+1

Loop

3Dcategorycheck.close

Col.Add "count", i



Then you can loop on your collection



For i = 1 to Col.item("count")

	response.Write col.item("varcat"+cstr(i))

Next



Or access one element on your collection



response.Write col.item("varcat1")



Regards







-----Message d'origine-----

De : Spencer Saunders [mailto:ssaunders@i...]

Envoyé : jeudi 9 août 2001 07:07

À : Access ASP

Objet : [access_asp] defining multiple variables in a loop







I am having a problem with getting a number of variables set in a loop. 

I keep getting a syntax error and I can't figure out how to fix it.



code.



varmaxcount=3Dcategorycheck.recordcount

i=3D1

Do While NOT i > varmaxcount

varcat&i=3Dcategorycheck("category")

categorycheck.movenext

i =3D i+1

Loop



But I am getting a syntax error on the line with 

"varcat&i=3Dcategorycheck("category")".

What is the syntax to append a numeric value onto the end of a variable 

name???

in the end I would like a list of variables that look lie this

var1=3D"articles"

var2=3D"general"

etc...





TIA



spence



=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

=3D=3D=3D=3D=3D=3D::



Spencer Saunders

www.spencersaunders.com

ssaunders@i...















  Return to Index