Code: Select all
title.s = "Little File Editor"
EnableJS
document.title = v_title
DisableJS
Procedure FileRead(Status, Filename$, File, Size)
If Status = #PB_Status_Loaded
buffer.s = ""
While Not Eof(4)
line.s = ReadString(4)
buffer = buffer + line + Chr(10)
Wend
CloseFile(4)
SetGadgetText(1, buffer)
ElseIf Status = #PB_Status_Error
Debug "Error when loading the file: " + Filename$
EndIf
EndProcedure
Procedure FileOpen()
If NextSelectedFile()
ReadFile(4, SelectedFileID(), @FileRead(), #PB_LocalFile)
EndIf
EndProcedure
Procedure FileOpenReq()
OpenFileRequester("*.txt", @FileOpen())
EndProcedure
Procedure SetEditActive()
EndProcedure
; ------------------------------------------------------------------------------------
; Main program
; ------------------------------------------------------------------------------------
OpenWindow(0, 0, 0, 520, 590, title)
EditorGadget(1, 10, 10, 500, 500)
ButtonGadget(2, 10, 520, 220, 30, "Open a text file...")
ButtonGadget(3, 250, 520, 220, 30, "Create new text file...")
BindGadgetEvent(2, @FileOpenReq())
BindGadgetEvent(3, @SetEditActive())
I now use
Code: Select all
buffer = buffer + line + Chr(10)
Also tried chr(13) and chr(13) + chr(10).
How can I achieve that a blank line in the input file is 1 blank liune in the gadget?