473,395 Members | 1,403 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,395 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 4290
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: 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
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.