Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

How to open file using variable?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS
View previous topic :: View next topic  
Author Message
almatea

Bascom Member



Joined: 22 Oct 2005
Posts: 64

poland.gif
PostPosted: Fri Mar 23, 2007 10:45 am    Post subject: How to open file using variable? Reply with quote

Hi,

I would like to open a file using syntax: OPEN file FOR MODE as #channel.

For example:

Open "File.txt" For Append As #4

Is it possible to use string variable instead of "File.txt"?

Does anybody know how to do this?


Best Regards
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Fri Mar 23, 2007 7:30 pm    Post subject: Reply with quote

Hi.

The following code snippet from Josef's "Flashcard-Demo.bas" shows how to do this, if I read it right:

Code:

'dim some test variables
Dim S As String * 60 , Fl As String * 12 , Ff As Byte
Dim Sdatetime As String * 18
Fl = "test.txt"
S = "test this"

'Now we are getting to it
'We can specify a file handle with #1  or #2 etc. or we can ask for a free
' file handle with the FreeFile function. It will return a free handle if there is one.

Ff = Freefile()                                             ' get a file handle

'With this file handle we refer to a file
Open Fl For Output As #ff                                   ' open fikle for output
'  we need to open a file  before we can use the file commands
'  we open it for OUTPUT, INPUT , APPEND or BINARY
'  In this case we open it for OUTPUT because we want to write to the file.
'  If the file existed, the file would be overwritten.
Print #ff , S                                               ' print some data
Print #ff , S
Print #ff , S
Print #ff , "A constant" ; S
Testsb Ff
Close #ff                                                   ' close file

'A file opened if OUTPUT mode is convenient to write string data too
'The next beta will support WRITE too

'We now created a file that contains 3 lines of text.
'We want to append some data to it
S = "this is appended"
Open Fl For Append As #150                                  ' we specify the file number now
Print #150 , S
Close #150
 


The above is line number 80 through 113. As you can see, there is a line

Code:

Open Fl For Output As #ff
 


F1 is a variable defined in line 83.

I would imagine that there is a way where you can read some data from your stroage device (SD card, or whatever) that would have information you could read into a variable. Just be sure that the variable is a string.

Hope this helps.

Pete
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum