Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 29, 2021 5:04:33 GMT -5
I know this has probably been asked a zillion times before but I cannot locate an answer on the forum. I need to do the following:
1. Allow the user to input text into a texteditor control. The text can include linefeeds (enter) 2. Write the text to a file. 3. Read back the file keeping the linefeeeds intact.
I have no problem with points 1 and 2 above but I just cannot seem to get step 3 right.
When I look at the written out file using notepad, it looks right but when I read it back, all I get is the first record.
I have tried binary files and sequential files but no luck.
I have tried scanning the text and replacing the two zero characters at the end of the record with chr$(13)+chr$(10) but still no luck.
When I try to read multiple records off the binary file, EOF is not actioned and I get a "read beyond end" error..
I know it can be done but I just am not seeing the wood for the trees.
It seems such a simple thing to do but I think I am getting too old.... :-)
|
|
|
Post by Rod on Aug 29, 2021 5:15:52 GMT -5
You are probably using the wrong input command. There are several forms have a browse at the help file. You probably want input$(#filehandle,lof(#filehandle))
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 29, 2021 5:43:58 GMT -5
OK, got it working using the "print #handle, "!contents #handle";" command. I would however still like to know how to do point 3 of my list in my first post....
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 29, 2021 5:45:34 GMT -5
Hi Rod thanks! I will give it a go ....
|
|
|
Post by Walt Decker on Aug 29, 2021 11:28:09 GMT -5
Here is one way:
TEXTEDITOR #TST.EDT, 5, 5, 250, 250 BUTTON #TST.SAV, "SAVE", BTN.SAV, UL, 5, 265, 45, 25 BUTTON #TST.LOD, "LOAD", BTN.LOD, UL, 60, 265, 45, 25 OPEN "CRLF" FOR WINDOW AS #TST PRINT #TST, "TRAPCLOSE END.IT" WAIT
'----------------------------------------------------------------------- '-----------------------------------------------------------------------
SUB END.IT WinHndl$
CLOSE #TST END
END SUB
'----------------------------------------------------------------------- '-----------------------------------------------------------------------
SUB BTN.SAV BtnHndl$
TxtStr$ = "" PRINT #TST.EDT, "!contents? TxtStr$"
OPEN "CRLF.TXT" FOR OUTPUT AS #1 PRINT #1, TxtStr$ CLOSE #1 PRINT #TST.EDT, "!cls"
END SUB
'------------------------------------------------------------------ '------------------------------------------------------------------
SUB BTN.LOD BtnHndl$
OPEN "CRLF.TXT" FOR BINARY AS #1 PRINT #TST.EDT, INPUT$(#1, lof(#1)) CLOSE #1 END SUB
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 30, 2021 5:55:37 GMT -5
Thanks Walt!!
|
|
|
Post by Walt Decker on Aug 30, 2021 13:59:03 GMT -5
You are welcome. Did you get your take on it working?
|
|
|