End-of-line characters

Just starting out? Need help? Post your questions and find answers here.
hotcore
Posts: 14
Joined: Wed Jun 29, 2016 10:18 am

End-of-line characters

Post by hotcore »

My first little project (half the way):

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())
When I click the button "Open a text file..." and choose a text file, I see that every blank line appears 3 times in the EditorGadget.
I now use

Code: Select all

 buffer = buffer + line + Chr(10)
in order to create a newline character to add multiple lines to the gadget.
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?
hotcore
Posts: 14
Joined: Wed Jun 29, 2016 10:18 am

Re: End-of-line characters

Post by hotcore »

Just found a solution using:

Code: Select all

      char.c = ReadCharacter(4)
      buffer = buffer + Chr(char)
However, still curious why the other solution does not work ...
Post Reply