[futurebasic] Re: [FB] Reading files... (Writing files is working)

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

From: Stu Cram <stu@...>
Date: Thu, 22 Dec 2005 21:46:32 -0600
On Dec 22, 2005, at 6:13 PM, <bheibert@...> wrote:
> I got this code to read files created with my program
>
> DIM fo1$
> DEF OPEN "HBSfHBas"
> fo1$ = FILES$(_fOpen,"HBSfHBAS","Open HBasic file...",refNumVar%)
> OPEN "I",2,fo1$
> LINE INPUT #2,txt$
> PRINT #1, txt$
> EDIT FIELD #_cEdit,txt$
>
> But it isn't working
> -----------------------------

Do you want some help or are you just boasting that it doesn't work. ;-)

My last answer earlier today to your implied question gave 2 reasons 
why it won't work and several other tips to check for. Hope you've gone 
over that, tried it out and were successful. Here's another demo 
program for you to look at. This one shows how to save an edit field 
line by line to an arbitrary text file and later how to read a text 
file back into an edit field. There is a subroutine to do each task of 
course. The demo also shows how to attach a scroll bar to the edit 
field, how to add a 'Select all' option to the edit menu, and how to 
make and use a few buttons in your window.

Merry Christmas - this will be your last present for a while.
-Stu


' Demo for BH to write text files with lines from edit field
'     and to fill an edit field with lines from a text file.
' By Stu Cram, for FutureBASIC Digest, Dec 23, 2005
' Extras:  a scroll bar; a 'Select All' item in edit menu; push buttons
'~'1
LOCAL FN SaveEditFieldToTextFile( efNum )
DIM fName$, refNumVar%
DIM efHndl&, dataLine$, lineNum
fName$ = FILES$(_fsave, "Enter a file name:", "", refNumvar% )
IF fName$ = "" THEN EXIT FN
DEF OPEN "TEXTttxt"
OPEN "O", 1, fName$,,refNumVar%
efHndl& = TEhandle( efNum )
FOR lineNum = 1 TO efHndl&..TEnLines%
dataLine$ = EDIT$( efNum, lineNum )
PRINT #1, dataLine$
NEXT lineNum
CLOSE #1
END FN
'~'1OPEN "I", 2, filename
LOCAL FN ReadTextFileIntoEditField( efNum )
DIM fName$, refNumvar%, dataLine$
fName$ = FILES$(_fopen, "TEXT", "Select a file:", refNumvar% )
IF fName$ = "" THEN EXIT FN
OPEN "I", 2, fName$,,refNumVar%
EDIT$( efNum ) = ""
WHILE NOT EOF( 2 )
LINE INPUT #2, dataLine$
EDIT$( efNum, _maxInt,_maxInt ) = dataLine$ + chr$(13)
WEND
CLOSE #2
SetSelect _maxInt, _maxInt
END FN
'~'1
LOCAL FN init
DIM txt$
DIM rtn$
rtn$ = CHR$(13)
txt$ = "Pistachio" + rtn$
txt$ += "Chocolate" + rtn$
txt$ += "Vanilla" + rtn$
txt$ += "Peanut Butter, with chocolate chips" + rtn$
txt$ += "Peach Passion" + rtn$
WINDOW 1, "Text File Demo #4 - To/From Edit Field", (0,0)-(500,500), 
_doc
TEXT _Courier, 12, 0
EDIT FIELD 666, txt$, (40,40)-(340,460), _framed
SCROLL BUTTON -666,1,1,100,10,(341,40)-(357,460)
SetSelect _maxInt, _maxInt
BUTTON 1,_activeBtn,"Save File", (380, 40)-(480, 60), _push
BUTTON 2,_activeBtn,"Read File", (380, 80)-(480,100), _push
BUTTON 3,_activeBtn,"Quit",      (380,120)-(480,140), _push
MENU 1,0,1,"File"
MENU 1,1,1,"Quit/Q"
EDIT MENU 2
MENU 2,8,1,"Select All/A"
END FN
'~'1
LOCAL FN doDialog
DIM evtCode, subCode
evtCode = DIALOG( 0 )
subCode = DIALOG( evtCode )
SELECT evtCode
CASE _wndClose : END
CASE _btnClick
SELECT subCode
CASE 1 : FN SaveEditFieldToTextFile( 666 )
CASE 2 : FN ReadTextFileIntoEditField( 666 )
CASE 3 : END
END SELECT
END SELECT
END FN
'~'1
LOCAL FN doMenu
DIM menuNum, itemNum
menuNum = MENU( 0 )
itemNum = MENU( 1 )
IF menuNum=1 and itemNum=1 THEN END
IF menuNum=2 and itemNum=8 THEN SetSelect 0, _maxInt
END FN
'~'1
' MAIN PROGRAM...
FN init
ON DIALOG FN doDialog
ON MENU FN doMenu
DO
HandleEvents
UNTIL 0