making variables

  • Thread starter Thread starter andrews
  • Start date Start date
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
 
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.
 
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.
 
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
 
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
 
Back
Top