|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to create var with same name but another index?Hi,
I want to create an unknown number of variables, depending of the value of another variable (amounvar).. The created variables must have the name: var1, var2 etc ... I never know in advance 'amountvar'. I tried this but doesn't work: ..... amountvar=30 for i=1 to amountvar dim var & i next Thanks for help Britt Britt,
This is what arrays are for. Kerry Moorman Show quoteHide quote "Britt" wrote: > Hi, > > I want to create an unknown number of variables, depending of the value of > another variable (amounvar).. > The created variables must have the name: var1, var2 etc ... I never know in > advance 'amountvar'. > > I tried this but doesn't work: > ..... > amountvar=30 > for i=1 to amountvar > dim var & i > next > > Thanks for help > Britt > > > try using arrays or an arraylist. in an array, you specify the size (which
can be expanded during execution)...for example Dim arrInt(5) as Integer that creates 6 integer variables, arrInt(0), arrInt(1), ..., arrInt(5). to use those variables, you just say exactly what i did above, arrInt(index number). you could also use an array list object Dim arrInt as New ArrayList arrInt.Add(some object or value here) var = arrInt(index) and since they are collections, you can use them in for loops hope this helps -- -iwdu15 It sounds like an array.
amountVar = 30 Dim myVariables(amountVar) Now you have access to 31 variables, numbered from myVariables(0) to myVariables(30). ----- Tim Patrick Start-to-Finish Visual Basic 2005 Show quoteHide quote > Hi, > > I want to create an unknown number of variables, depending of the > value of > another variable (amounvar).. > The created variables must have the name: var1, var2 etc ... I never > know in > advance 'amountvar'. > I tried this but doesn't work: > .... > amountvar=30 > for i=1 to amountvar > dim var & i > next > Thanks for help > Britt You can't. Use an array or a generic list.
Robin S. Show quoteHide quote "Britt" <fbf***@dvsv.qs> wrote in message news:%23%23cMS%23DBHHA.3380@TK2MSFTNGP04.phx.gbl... > Hi, > > I want to create an unknown number of variables, depending of the value of > another variable (amounvar).. > The created variables must have the name: var1, var2 etc ... I never know > in advance 'amountvar'. > > I tried this but doesn't work: > .... > amountvar=30 > for i=1 to amountvar > dim var & i > next > > Thanks for help > Britt > > Thanks all
Show quoteHide quote "RobinS" <RobinS@NoSpam.yah.none> schreef in bericht news:yJqdnS3I2sCmKc7YnZ2dnUVZ_smdnZ2d@comcast.com... > You can't. Use an array or a generic list. > > Robin S. > > "Britt" <fbf***@dvsv.qs> wrote in message > news:%23%23cMS%23DBHHA.3380@TK2MSFTNGP04.phx.gbl... >> Hi, >> >> I want to create an unknown number of variables, depending of the value >> of another variable (amounvar).. >> The created variables must have the name: var1, var2 etc ... I never know >> in advance 'amountvar'. >> >> I tried this but doesn't work: >> .... >> amountvar=30 >> for i=1 to amountvar >> dim var & i >> next >> >> Thanks for help >> Britt >> >> > >
VB Controls In VB2005
difference between dataAdapter.InsertCommand/dataAdapter.SelectCom Get the value of a cell when row changes in DataGridView remove xml file root tag how to capture enter key without affrecting copy paste kcust keys max length for tooltip add xml validation schema in the xml file Using variable names to change labels Why has debug.print stopped working??? remove xml file namespace attribute |
|||||||||||||||||||||||