473,386 Members | 1,668 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,386 software developers and data experts.

create varible at runtime

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
Aug 11 '08 #1
2 2227
AFAIK what you try to do is not possible ( or i am sure missing something )
however you could acomplish your task by using a array of doubles or if you
need to access the values as key value pairs you could go for a hashtable
both of them would work fine .

hth

Michel

"Husam" <Hu***@discussions.microsoft.comschreef in bericht
news:B3**********************************@microsof t.com...
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

Aug 11 '08 #2
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
Aug 11 '08 #3

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

Similar topics

2
by: Jack | last post by:
Hello, Under is C procedure: #include<stdio.h> #include<conio.h> void ab(int x) { if(x<5) { ab(x+1); printf("%d ",x);
1
by: Abby Lee | last post by:
I hard coded "TheYear" (the table) and "MonthPD" (a field) into my script to make sure the query worked (it did)...so now I want to replace an actual year (table) with varible which the next step...
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...
3
by: cql90 | last post by:
Hi all PRO, I don't know how to create the MSAccess database in the runtime with C#, Are there any body know how to do this? I am pretty sure that all of you know how to do it, except me :( ....
6
by: The8thSense | last post by:
how to declare static varible and static method inside a class ? i try "public static ABC as integer = 10" and it said my declaration is invalid Thanks
1
by: Peter | last post by:
Does anybody know how to convert a string to a varible? For example, I have defined 2 structures Structure SS dim Name as string dim ID as short end structure Structure TT
7
by: MarkoH | last post by:
Wsdl.exe /server creates abstract class derived from WebService. Is there a way to create this class at runtime based on some WSDL file given at runtime ? What would be even better - creating...
2
by: Aido82 | last post by:
Hi, this is probably a stupid question. Im trying to declare a varible to have the value of that in a text box when i declare the varible is there a way to give it the value in a text box...
3
by: Sachin | last post by:
Hi Folks, I have one query in regarding const varible interpretaion by C/C++ compiler. How Compiler actually differentiate between normal stack varible and const varible during program execution?...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.