Loading ...
Sorry, an error occurred while loading the content.
 

Problem Texteditor reading/writing from/to a file

Expand Messages
  • Artur Davidjan
    Hello LB-Group,   I wonder if someone can help me with the Texteditor Control in a dedicated window. I try to simply read some text from a file called
    Message 1 of 3 , Jul 31, 2013
      Hello LB-Group,
       
      I wonder if someone can help me with the Texteditor Control in a dedicated window.
      I try to simply read some text from a file called "memo.txt" and then after some changes were made, simply save the contents of texteditor-control to this file.
       
      I receive a "File Handle error" when writing to the file, but I checked the syntax now several times with the help files and everything seems to be fine.
       
      Please have a look. I appreciate any comment or help.
       
      Code:
       
      SUB memodialog
          
          timer 0
          
          ' shows the memodialog and stuff like that
       
          ForegroundColor$ = "Black"
          BackgroundColor$ = "Brown"


          True = 1 : False = 0


      [memoWindowSetup]
          
          WindowWidth = 910 : WindowHeight = 521
          UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
          UpperLeftY = INT((DisplayHeight-WindowHeight)/2)


      [memoControlSetup]
          stylebits   #memodialog.saveandexitBTN, _BS_MULTILINE, 0, 0, 0
          button      #memodialog.saveandexitBTN, "&Save a. Exit", [saveandexitBTNclick], UL, 800, 425, 80, 30
          
          TexteditorColor$ = "White"
          texteditor  #memodialog.te1, 15, 15, 870, 390


          Open "Memo Dialog:" for window as #memodialog
          #memodialog "trapclose [quit.memo]"
          #memodialog "font ms_sans_serif 10"
         
          ' read memo.txt and store text in texteditor1
          open "memo.txt" for input as #f
          
              'input #f, tmp$
              while eof(#f) = 0
                  
                  line input #f, tmp$
                  
                  print #memodialog.te1, tmp$
                  'print #memodialog.te1, chr$(13)
              wend        
          close #f
          
          'print #memodialog.te1, "!contents tmp$";
          
       
      [memotimer]


          timer 75, [checkmemokeypress]
          scan
          wait


      [loop]
          Wait
          
      [checkmemokeypress]


          if CheckKey(_VK_ESCAPE) then goto [saveandexitBTNclick]
          
          goto [memotimer]


      [quit.memo]


          timer 0
          close #memodialog


      [saveandexitBTNclick]


          timer 0
          
          'write text content of texteditor1 to memo.txt file
          ' debugger throws here the error message "File handle error"
      ' when readin the texteditor content into a variable called string$
          
          print #memodialog.te1, "!contents? string$"
          
          
          open "memo.txt" for output as #f2
              print #f2, string$
          close #f2
          
          
          goto [quit.memo]


      END SUB


      ---
      Alle Postfächer an einem Ort. Jetzt wechseln und E-Mail-Adresse mitnehmen! Rundum glücklich mit freenetMail

      [Non-text portions of this message have been removed]
    • green8819
      Hello, I wrote a sample, Read/Write , Files page
      Message 2 of 3 , Aug 1, 2013
        Hello,
        I wrote a sample, "Read/Write", Files page

        --- In libertybasic@yahoogroups.com, Artur Davidjan <ar.davidjan@...> wrote:
        >
        > Hello LB-Group,
        >  
        > I wonder if someone can help me with the Texteditor Control in a dedicated window.
        > I try to simply read some text from a file called "memo.txt" and then after some changes were made, simply save the contents of texteditor-control to this file.
        >  
        > I receive a "File Handle error" when writing to the file, but I checked the syntax now several times with the help files and everything seems to be fine.
        >  
        > Please have a look. I appreciate any comment or help.
        >  
        > Code:
        >  
        > SUB memodialog
        >     
        >     timer 0
        >     
        >     ' shows the memodialog and stuff like that
        >  
        >     ForegroundColor$ = "Black"
        >     BackgroundColor$ = "Brown"
        >
        >
        >     True = 1 : False = 0
        >
        >
        > [memoWindowSetup]
        >     
        >     WindowWidth = 910 : WindowHeight = 521
        >     UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
        >     UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
        >
        >
        > [memoControlSetup]
        >     stylebits   #memodialog.saveandexitBTN, _BS_MULTILINE, 0, 0, 0
        >     button      #memodialog.saveandexitBTN, "&Save a. Exit", [saveandexitBTNclick], UL, 800, 425, 80, 30
        >     
        >     TexteditorColor$ = "White"
        >     texteditor  #memodialog.te1, 15, 15, 870, 390
        >
        >
        >     Open "Memo Dialog:" for window as #memodialog
        >     #memodialog "trapclose [quit.memo]"
        >     #memodialog "font ms_sans_serif 10"
        >    
        >     ' read memo.txt and store text in texteditor1
        >     open "memo.txt" for input as #f
        >     
        >         'input #f, tmp$
        >         while eof(#f) = 0
        >             
        >             line input #f, tmp$
        >             
        >             print #memodialog.te1, tmp$
        >             'print #memodialog.te1, chr$(13)
        >         wend        
        >     close #f
        >     
        >     'print #memodialog.te1, "!contents tmp$";
        >     
        >  
        > [memotimer]
        >
        >
        >     timer 75, [checkmemokeypress]
        >     scan
        >     wait
        >
        >
        > [loop]
        >     Wait
        >     
        > [checkmemokeypress]
        >
        >
        >     if CheckKey(_VK_ESCAPE) then goto [saveandexitBTNclick]
        >     
        >     goto [memotimer]
        >
        >
        > [quit.memo]
        >
        >
        >     timer 0
        >     close #memodialog
        >
        >
        > [saveandexitBTNclick]
        >
        >
        >     timer 0
        >     
        >     'write text content of texteditor1 to memo.txt file
        >     ' debugger throws here the error message "File handle error"
        > ' when readin the texteditor content into a variable called string$
        >     
        >     print #memodialog.te1, "!contents? string$"
        >     
        >     
        >     open "memo.txt" for output as #f2
        >         print #f2, string$
        >     close #f2
        >     
        >     
        >     goto [quit.memo]
        >
        >
        > END SUB
        >
        >
        > ---
        > Alle Postfächer an einem Ort. Jetzt wechseln und E-Mail-Adresse mitnehmen! Rundum glücklich mit freenetMail
        >
        > [Non-text portions of this message have been removed]
        >
      • green8819
        I wrote the sample for my own practice. Since you are using texteditor, perhaps a simpler solution would be to add another Menu, File Open Save
        Message 3 of 3 , Aug 1, 2013
          I wrote the sample for my own practice.
          Since you are using texteditor, perhaps a simpler solution would be to add another Menu, > File > Open > Save As.....etc.

          --- In libertybasic@yahoogroups.com, "green8819" <skynetmike@...> wrote:
          >
          > Hello,
          > I wrote a sample, "Read/Write", Files page
          >
          > --- In libertybasic@yahoogroups.com, Artur Davidjan <ar.davidjan@> wrote:
          > >
          > > Hello LB-Group,
          > >  
          > > I wonder if someone can help me with the Texteditor Control in a dedicated window.
          > > I try to simply read some text from a file called "memo.txt" and then after some changes were made, simply save the contents of texteditor-control to this file.
          > >  
          > > I receive a "File Handle error" when writing to the file, but I checked the syntax now several times with the help files and everything seems to be fine.
          > >  
          > > Please have a look. I appreciate any comment or help.
          > >  
          > > Code:
          > >  
          > > SUB memodialog
          > >     
          > >     timer 0
          > >     
          > >     ' shows the memodialog and stuff like that
          > >  
          > >     ForegroundColor$ = "Black"
          > >     BackgroundColor$ = "Brown"
          > >
          > >
          > >     True = 1 : False = 0
          > >
          > >
          > > [memoWindowSetup]
          > >     
          > >     WindowWidth = 910 : WindowHeight = 521
          > >     UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
          > >     UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
          > >
          > >
          > > [memoControlSetup]
          > >     stylebits   #memodialog.saveandexitBTN, _BS_MULTILINE, 0, 0, 0
          > >     button      #memodialog.saveandexitBTN, "&Save a. Exit", [saveandexitBTNclick], UL, 800, 425, 80, 30
          > >     
          > >     TexteditorColor$ = "White"
          > >     texteditor  #memodialog.te1, 15, 15, 870, 390
          > >
          > >
          > >     Open "Memo Dialog:" for window as #memodialog
          > >     #memodialog "trapclose [quit.memo]"
          > >     #memodialog "font ms_sans_serif 10"
          > >    
          > >     ' read memo.txt and store text in texteditor1
          > >     open "memo.txt" for input as #f
          > >     
          > >         'input #f, tmp$
          > >         while eof(#f) = 0
          > >             
          > >             line input #f, tmp$
          > >             
          > >             print #memodialog.te1, tmp$
          > >             'print #memodialog.te1, chr$(13)
          > >         wend        
          > >     close #f
          > >     
          > >     'print #memodialog.te1, "!contents tmp$";
          > >     
          > >  
          > > [memotimer]
          > >
          > >
          > >     timer 75, [checkmemokeypress]
          > >     scan
          > >     wait
          > >
          > >
          > > [loop]
          > >     Wait
          > >     
          > > [checkmemokeypress]
          > >
          > >
          > >     if CheckKey(_VK_ESCAPE) then goto [saveandexitBTNclick]
          > >     
          > >     goto [memotimer]
          > >
          > >
          > > [quit.memo]
          > >
          > >
          > >     timer 0
          > >     close #memodialog
          > >
          > >
          > > [saveandexitBTNclick]
          > >
          > >
          > >     timer 0
          > >     
          > >     'write text content of texteditor1 to memo.txt file
          > >     ' debugger throws here the error message "File handle error"
          > > ' when readin the texteditor content into a variable called string$
          > >     
          > >     print #memodialog.te1, "!contents? string$"
          > >     
          > >     
          > >     open "memo.txt" for output as #f2
          > >         print #f2, string$
          > >     close #f2
          > >     
          > >     
          > >     goto [quit.memo]
          > >
          > >
          > > END SUB
          > >
          > >
          > > ---
          > > Alle Postfächer an einem Ort. Jetzt wechseln und E-Mail-Adresse mitnehmen! Rundum glücklich mit freenetMail
          > >
          > > [Non-text portions of this message have been removed]
          > >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.