Dim a Variable from a string???Possible?? 
Author Message
 Dim a Variable from a string???Possible??

i want to read my variable names from a file or database.
is it possible to do sth like:

dim rs!name as string [len(rs!name)]

where rs!name is for example "Adress" ?

I know there's a way, but I forgot how.....



Sun, 16 Sep 2001 03:00:00 GMT  
 Dim a Variable from a string???Possible??
You can "kind of" do this using a collection.  Try the following code:

    Dim c As New Collection
    Call c.Add(rs!value,rs!name)        'don't try to put a duplicate
in, though!

Afterwards, to get the value out, you would have to do this:

    Debug.Print c.Item(rs!name)

This is the closest I can think of...

-Rob Hajicek
 SevenStar Technologies
______________________________________________________________________

SEVENSTAR TECHNOLOGIES * PO Box 937 * St. Louis, MO 63011-0937

**** OBJECT BRIEFCASE for VB 6.0 and VB 5.0 is now available!
**** A PROFESSIONAL control and code library add-in!
**** Create your own code wizards!  Add error handling to your code!
**** Free trial version at: http://www.SevenStarTech.com/download.htm
______________________________________________________________________

Quote:

> i want to read my variable names from a file or database.
> is it possible to do sth like:

> dim rs!name as string [len(rs!name)]

> where rs!name is for example "Adress" ?

> I know there's a way, but I forgot how.....



Sun, 16 Sep 2001 03:00:00 GMT  
 Dim a Variable from a string???Possible??


Quote:
>i want to read my variable names from a file or database.
>is it possible to do sth like:

>dim rs!name as string [len(rs!name)]

>where rs!name is for example "Adress" ?

>I know there's a way, but I forgot how.....

Not in VB, but in FoxPro or dBase or Clipper with the dreaded "&"
(=Makroexpansion). But still not a great programming style ;-)

Thomas



Sun, 16 Sep 2001 03:00:00 GMT  
 Dim a Variable from a string???Possible??
Aren'y you always going to find this impossible in a compiled language,
where the variables namespace is not available to you. Once compiled,
variable names don't mean anything

I suppose that if you really wanted to you could set up some kind of binding
structure which would bind you variables to something in a database (a bit
like the DFX mechanism used by DAO for C++), but it would be a lot of work,
and still requires recompilation if the variables change.

Graham

Quote:


>>i want to read my variable names from a file or database.
>>is it possible to do sth like:



Mon, 17 Sep 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Dim a Variable from a string???Possible??

2. Dim a Variable from a string???Possible??

3. dynamically dim a variable ie dim "variable"&n

4. Newbie Question: Dim A() as String /Dim A as String()

5. dim string to dim form

6. Executing a String Variable - Possible?

7. Dim'ing a list of variables

8. Problem dimming a variable as a database!

9. Dim variable

10. DIM statement using variables

11. Random Automation Errors with Dim variable

12. converting an object variable (name of a file) into a string variable

 

 
Powered by phpBB® Forum Software