Husam wrote:
Hi EveryBody:
I am using vb.net 2005 and the following code trying to create varible at
runtime:
For n=1 to 4
dim v+n.tostring(n) as double
Next n
the resone behaind using the previous code is to create
Dim v1(4) as double
dim v2(4) as double
dim v3(4) as double
dim v4(4) as double
but it dose not work,Can some body help me or direct me how can I do so?
regard's
Husam
What Michael says is true, it's not possible to create variables at
runtime. It simply doesn't make sense to have dynamic variables in a
compiled language.
There are several options for accomplishing something that you can use
similar to dynamic variables. Here are some:
1. A two dimensional array:
Dim v(3, 3) As Double
v(0, 0) = 3.14
v(3, 3) = 42
2. A jagged array, i.e. an array of arrays.
3. A list or arrays:
Dim v As new List(Of Double())
4. A list of lists:
Dim v As new List(Of List(Of Double))
v.Add(new List(Of Double)())
v(0).Add(3.14)
5. A dictionary of arrays:
Dim v As new Dictionary(Of Integer, Double())
6. A Dictionary of lists:
Dim v As New Dictionary(Of Integer, List(Of Double))
v(42) = new List(Of Double)()
v(42).Add(3.14)
....and so on. It all depends on what you want to use it for.
It would perhaps be better if you explained what it is that you want to
accomplish, instead of asking about how to do it the way that you think
that it should be done...
--
Göran Andersson
_____
http://www.guffa.com