making variables

A

andrews

Hi,
I have a question (maybe a stupid one)
I have too make some variables like
dim matrix5(5,5) as integer
dim matrix6(6,6) as integer
......
dim matrix10(10,10) as integer
this can be done but I want a shorter way like

dim str as string
dim i as integer

for i = 5 to 10
str = "matrix" & i.tostring
dim str(i,i) as integer
next i

but this gives a error
is it possible to do somthing like this without a error
it is long ago but i think it could be make in dbase3
thanks for any response
 
A

Andrew Morton

andrews said:
I have a question (maybe a stupid one)
I have too make some variables like
dim matrix5(5,5) as integer
dim matrix6(6,6) as integer
.....
dim matrix10(10,10) as integer
this can be done but I want a shorter way like

dim str as string
dim i as integer

for i = 5 to 10
str = "matrix" & i.tostring
dim str(i,i) as integer
next i

but this gives a error
is it possible to do somthing like this without a error
it is long ago but i think it could be make in dbase3
thanks for any response

What do you ultimately want to do with those arrays? A different type of
variable might be more suitable.

You can have an array of arrays:

Dim a(10)(,) As Integer
For i = 5 To 10
ReDim a(i)(i, i)
Next

although it makes me cringe to do that.

Or you could write a program to output the text you need to specify the
variables and paste that into your code.
 
A

andrews

What I want is that I can make many arrays of different dimensions on a
easy (short) way.
Sorry, there is no satisfaction with the given answers.
Maybe it is impossible.
Thanks any way.
 
C

Cor Ligthert[MVP]

Andrew,

Sorry I pasted in the wrong answer.

Arrays of different dimensions is an old way.

Now those things are called collections or lists.

By instance
Dim myList as new List(of String)

is in fact an array of Strings,

Although there is also the oldest one in Net the ArrayList, which is in fact
the base of those, which is an List(array) of objects

Success,

Cor
 
M

Michel Posseth [MCP]

I would like to add to that that now in VB 10 there is also the option to
create in a easy way a "true" matrix

XXXXXXXXXXXXXXXXXXXX
XXXXXX XXXX XXX XXXX
XX XXXX XXX XXXXXXXXX
XXXX XXXXXXXXXX
XXXX XXXXXX

where every X could be of a different datatype

You can acomplish this with a dictionary type and the new generic Tuple
class


HTH


Michel Posseth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top