[futurebasic] Re: [FB] Write & Read files

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2005 : Group Archive : Group : All Groups

From: Stu Cram <stu@...>
Date: Tue, 20 Dec 2005 21:44:04 -0600
On Dec 20, 2005, at 8:29 PM, <bheibert@...> wrote:
> Hi,
> I know how to dislay open & save dialog boxes
> but I don't know how to open a text file or save a text file
>
> I don't have the manuals with me I am in Mexico :-)
> I looked at the online help and all I saw was
>
> filename$ = FILES$(_fOpem,"Open file...",refNumVar%)
>
> Sorry
> Brian
> --
>

Gee Brian - You asked almost the same thing on Nov 9 and were given an 
working demo on Nov 14 for writing (saving) to a text file. It should 
be in you saved mail messages, isn't it? You do save answers everyone 
gives you, don't you.


Here's that answer again (but with one change/error for you to figure 
out yourself).

And it also uses 3 small arrays of sample data values. Do you 
understand the importance or concept of arrays? You didn't answer that 
before so I'm assuming it's new territory. This could be a gentle 
example about arrays as well as writing to a text file.

Enjoy the beaches in Mexico while you study this.  ;-)

You may also want to look at the BYH-BASIC Interpreter posted to this 
list on Nov 22 which contains routines for reading a text file into an 
edit field and for writing the lines of an edit field out to a disk 
file. But again, you should already have that. If not, check the 
archives. Again.

 From Stu the Canuck, in Canada where it was -29 degrees a few nights 
ago. Today it's a balmy -12.

------------------------------------

>> Date: Mon, 14 Nov 2005 16:49:25 -0600
>> To: Brian Heibert...
>>
>> As Brian Stevens and George Beckman pointed out, FB allows many
>> different ways to save various types of data. The KISS example
>> presented here is a full demo designed to test the save function send
>> earlier today. Hope you have looked at it and maybe tried testing it
>> yourself.
>>
>> Remember - that is the way to go: develop a subroutine and then test 
>> it
>> out in a small program before adapting it and meshing it into bigger
>> programs like the interpreter that you're keen on. Be sure each part
>> works as intended before adding it to a bigger program. And in cases
>> like this where it is new to you, start small and test often.
>>
>> Remember this example is just one (simple) way to save data in a file.
>> It may not be the most efficient but it works and is fairly easy to
>> program. Just changed the PRINT #1 ... instructions as needed. (You 
>> may
>> also want to try the more modern version using a file specification
>> record; if so, check the HELP files.)
>>
>> Hope this helps a bit.
>> - Stu C.
>>
>> '============================================
>> ' Demo program for writing to a TEXT file - Nov 14, 2005 / SNC-OGSS
>>
>> BEGIN GLOBALS
>> ' sample variables
>> DIM 31 gShoeBrand$(5)
>> DIM AS SHORT gShoeSoleSize(5) ' for an integer #
>> DIM AS SINGLE gShoePrice(5) ' for a 'real' # with decimal places
>> DIM 23 gName1$, gName2$
>> END GLOBALS
>>
>>
>> LOCAL FN SaveOurSoles
>> ' demo routine for writing to a TEXT file
>> DIM fileName$
>> DIM volRefNum%
>> DIM x
>>
>> ' STAGE 1...
>> ' Show the standard save file dialog ( see HELP for another version)
>> fileName$ = FILES$( _fSave, "Enter a file name...", "Untitled",
>> volRefNum% )
>> ' check if user chose 'Cancel' button
>> IF LEN( fileName$ ) = 0 THEN EXIT FN
>>
>> ' STAGE 2...   Open the actual file for output.
>> ' [ "O" ('oh' not 'zero') means Output mode in  OPEN "O", 1, ...  ]
>> ' [ The 1 will be the file # in other instructions.]
>> ' The DEF OPEN indicates what type of file it will be ---> TEXT ]
>> '     and what application will open it:  ttxt ---> SimpleText  ]
>> DEF OPEN "TEXTttxt"
>> OPEN "O", 1, fileName$, , volRefNum%
>>
>> ' STAGE 3...   Write data to the file
>> ' [ The simplest way is to print one item per line ]
>> ' [ Later another routine can read the items one per line ]
>> ' [ This makes it easy to see what was saved and to read later ]
>> ' You can print string and numeric variables or expresions
>> ' The variables usually would be global variables or parameters.
>> '  examples....
>> PRINT #1, fileName$
>> PRINT #1, DATE$
>> PRINT #1, ""
>> PRINT #1, gName1$ + " " + gName2$
>> PRINT #1, PI * 10  'PI is builtin:  ยน
>> PRINT #1, "---------"
>> ' This loop outputs 5 triples from some global array variables
>> FOR x = 1 TO 5
>> PRINT #1, gShoeBrand$(x)
>> PRINT #1, gShoeSoleSize(x)
>> PRINT #1, USING "###.##" ; gShoePrice(x)
>> NEXT x
>>
>> ' STAGE 4... Finish it up
>> CLOSE #1
>>
>> END FN
>>
>> ' rest of demo for saving a 'TEXT' file
>> '
>> LOCAL FN InitGlobalData
>> DIM x
>> DATA Belle, Zebubb
>> READ gName1$, gName2$
>>
>> DATA Natas, 12, 125.95
>> DATA LiveD, 7, 56
>> DATA Reficul, 13, 84.14
>> DATA Brimstone, 9, 6.66
>> DATA Ptory, 10, 99.99
>> FOR x = 1 to 5
>> READ gShoeBrand$(x), gShoeSoleSize(x), gShoePrice(x)
>> NEXT x
>> END FN
>>
>> '
>> '  MAIN PROGRAM  -
>> '
>>
>> WINDOW 1, "SAVE DEMO", (0,0)-(700,500), 5
>>
>> FN InitGlobalData
>>
>> FN SaveOurSoles
>>
>> PRINT "Press Cmd-Q to Quit"
>> DO
>>    HandleEvents
>> UNTIL gFBquit <> 0
>>
>> '============================================
>>
>> Here is what should be in the file that gets created...
>>
>> >>> My Sample File
>> >>> 11/14/05
>> >>>
>> >>> Belle Zebubb
>> >>>  31.4159265359
>> >>> ---------
>> >>> Natas
>> >>>  12
>> >>> 125.95
>> >>> LiveD
>> >>>  7
>> >>>  56.00
>> >>> Reficul
>> >>>  13
>> >>>  84.14
>> >>> Brimstone
>> >>>  9
>> >>>   6.66
>> >>> Ptory
>> >>>  10
>> >>>  99.99
>>
>> '============================================
>>
>>
>> > On Nov 9, 2005, at 9:27 PM, Brian Heibert wrote:
>> > I have no idea how to save a file in fb
>> >
>> > I guess I am lost
>> > I looked in the manuals
>> > I know how to display the file open & file save dialog boxes
>> > but not how to save files
>> >
>> > Brian H