Initializing variables from a file - How? 
Author Message
 Initializing variables from a file - How?

Can someone help me with this embarrasingly simple question - which for
some reason, the answer escapes me?  I'm trying to read in values from a
random access file and set my program variables to those values.  I'm using
the GetPrivateProfileString API call to get lines like "Apex=32".  I can
parse the string to get the initial part of the line (the variable name,
like "Apex"), and I can parse the string to get the second part (like 32).
I'm having trouble setting my program's variable (named "Apex") equal to
32.  I'd like to look at the first part of the string that I get from the
file ("Apex") and then set my program variable of the same name to the
value (32).  Does anyone have a suggestion for some code lines?  Thanks.
Rick Stanford



Wed, 14 Jul 1999 03:00:00 GMT  
 Initializing variables from a file - How?

You could try using collections, which enable you to have a 'named' array
where you recall items by name and not by position.

Dim MyVars As New Collection, ApexValue As Integer

        MyVars.Add key:='Apex", item:=32
...
        ApexValue = MyVars("Apex")
--
Francesc Hervada i Sala
Modul 4, Serveis Informatics, S. L.
Barcelona, Spain



Thu, 15 Jul 1999 03:00:00 GMT  
 Initializing variables from a file - How?


Quote:
> You could try using collections, which enable you to have a 'named' array
> where you recall items by name and not by position.

> Dim MyVars As New Collection, ApexValue As Integer

>    MyVars.Add key:='Apex", item:=32
> ...
>    ApexValue = MyVars("Apex")
> --

Hmmm.  That's a thought.  I'll give it a try.  It would also eliminate the
need for many global variables.  I wonder how that would affect resource
usage as well.  Thanks for the hint.  Regards.  Rick


Fri, 16 Jul 1999 03:00:00 GMT  
 Initializing variables from a file - How?


SNIP

Quote:
> You could try using collections, which enable you to have a 'named' array
> where you recall items by name and not by position.

Francesc -

I tried it and I'm still puzzled (rompecabeza as it were).  I'd like to
have something that works like the %filename function does on command lines
and in DOS batch files.  What I need to be able to do is use what is stored
in a variable, rather than the variable itself, to set the value of another
variable.  I know its confusing, but if I have a variable, named say,
"return_value1"  that holds the string "Apex" that I read from my disk
file, and another variable named, say "return_value2" that holds the
integer 32 which I also read from my disk file, I'd like to be able to set
my program variable (Apex) to 32 using these two variables.  The tricky
part is that I don't know ahead of time which program variable I can set
from the integer value I just got from the disk.  That's why I can't use
your "ApexValue = MyVars("Apex")" line.  I'm trying to avoid a very long
If...Elseif...Then or a long Select Case structure.  I'd like to be able to
look at return_value1 to see which program variable I can set, then set it.

Gracias para su ayuda.  Rick.



Sat, 17 Jul 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Declaring&initializing variables

2. Initialize a variable from a TextBox?

3. How to initialize variable of date type to blank

4. Variable not initialized

5. How to initialize a variable to 0.00?

6. Where should I initialize my variables? (VBA app)

7. How to initialize a local static variable?

8. initialize date variables

9. initializing global variables

10. How do I initialize static variables?

11. Initialize variables used in StoreNumberVar & FetchNumbervar

12. VB6: How to initialize a variable as a array structure / structure (type) array (see example)

 

 
Powered by phpBB® Forum Software