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

Dynamic Variable Declaration

pbb
Is it possible to declare a variable by referencing
another variable as the type?

Something like this:

'Declare variable to hold variable type
Dim strVariableType as String

'Set variable = to the value in a field from a datatable
strVariableType = dt("VarType")

'Declare new variable using a variable as the data type
Dim obj as strVariableType

I've been able to use the FindControl() function to
reference controls dynamically, but I haven't seen a
function to do this.
Jul 21 '05 #1
1 4289
No, because these declarations are checked at compile time.

You have two options, declare your variable as an Object and then it can
hold any value you want, regardless of the datatype, or you could use
Reflection to dynamically create variables (although this may only work for
fields, not variables inside a function).

"pbb" <pb*****@flowauto.com> wrote in message
news:09****************************@phx.gbl...
Is it possible to declare a variable by referencing
another variable as the type?

Something like this:

'Declare variable to hold variable type
Dim strVariableType as String

'Set variable = to the value in a field from a datatable
strVariableType = dt("VarType")

'Declare new variable using a variable as the data type
Dim obj as strVariableType

I've been able to use the FindControl() function to
reference controls dynamically, but I haven't seen a
function to do this.

Nov 22 '05 #2

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

Similar topics

2
by: Tommy Lang | last post by:
Hi everybody! I am trying to learn the basics of C++ myself and have a hard time understanding some stuff like pointers and references etc. I have created a small program that adds two numbers...
7
by: YGeek | last post by:
Is there any difference between declaring a variable at the top of a method versus in the code of the method? Is there a performance impact for either choice? What about if the method will return...
18
by: Brian Genisio | last post by:
I know I have done this in Java, but is there a way to do it in C++? Type B and C inherit from type A. In a function, I want to check an instance of A (which can also be B or C), to see what...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
11
by: Tim | last post by:
Why won't the declaration of a struct array work if I do it like this: 1 typedef struct 2 { 3 int pens; 4 int pencils; 5 } Stationers; 6 .........
0
by: pbb | last post by:
Is it possible to declare a variable by referencing another variable as the type? Something like this: 'Declare variable to hold variable type Dim strVariableType as String 'Set variable =...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
1
by: QryS | last post by:
Hi there I have a class within which i assign 2 dimension dynamic array of pointers which points to variable inside these class (variable is of type other class). Now to get into that variable...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.