Re: help !

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message ----- 
From: <rml at rubis.trix.net>
To: "EUforum" <EUforum at topica.com>
Subject: help !


> 
> 
> Hi people;
> 
>          I need some help...
>          It's possible to write a txt file with some variables names and 
> then read these variables and give values for them ?
> 

> 
> This results in :
> 
> data[1]
> data[2]
> data[3]
> 
> What I'm trying to obtain is
> 
> 1
> 2
> 3
> 
> Is this possible ?

Hi Rubens,
This is sort of possible. But before we go in to that, can I explain what your
code is doing now.

> For example:
> 
> I create a txt file with this tree lines only:
> 
> data[1]
> data[2]
> data[3]

Ok, so now we have a text file with three lines. Each line has the name of a
variable we want to use. This is fine, so let's continue.

> 
> Now, I read this file and "puts" in the screen:
> 
> ------------------------------------------------------------------------------

 Open the file for reading.
> arquivo=open(txt,"r")

 Initialize a sequence called 'txt'
> txt={}

 Initialize another sequence called 'data' to contain 3 empty sequences.
> data=repeat({},3)

Assign a value to each of the three subsequences.
> data[1]="1"
> data[2]="2"
> data[3]="3"
> 

> while 1 do
 Get the next byte/character from the file.
>        caracter=getc(arquivo)
 If we are at end-of-file then stop
>        if equal(caracter,-1) then exit end if
 Attach the character we just read to the end of the 'txt' sequence.
>        txt=append(txt,caracter)
 Repeat until end of file.
> end while

 Copy the 'txt' sequence to the screen.
> puts(1,txt)

In other words, all you have done is copy the contents of the text file to the
screen.

Now what I think you are asking for is a way to specify some variables by name
in a file, and use those variable names in a program at runtime. I guess I don't
know WHY you need to do this, and maybe if I understood that I could suggest a
way to achieve you goals.

As a start though you might look up Jiri's associative array library in the RDS
archive.

-- 
Derek

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu