473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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
Nov 9 '06 #1
5 825
Britt,

This is what arrays are for.

Kerry Moorman
"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
Nov 9 '06 #2
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
Nov 9 '06 #3
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
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

Nov 9 '06 #4
You can't. Use an array or a generic list.

Robin S.

"Britt" <fb****@dvsv.qswrote in message
news:%2********************@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


Nov 9 '06 #5
Thanks all

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:yJ******************************@comcast.com. ..
You can't. Use an array or a generic list.

Robin S.

"Britt" <fb****@dvsv.qswrote in message
news:%2********************@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



Nov 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Tuhin Kumar | last post by:
Hi, Oracle give the error ORA-01418 when I try to do the following; Create unique index t1_pk on TABLE1(EntryId DESC) ; If the I try to add primary key Contraint using the above index t1_pk...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
19
by: Lyle Fairfield | last post by:
MSDN Home > MSDN Library > Win32 and COM Development Data Access Microsoft offers many data access technologies to suit various development needs. This section of the MSDN Library contains...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
8
by: shira | last post by:
I have done a fair bit of searching, but haven't yet been able to find an explanation as to why one would set "ignore nulls" to "yes" when creating an index. I understand what it does (I think),...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.