Menu

Text file output

Help
Anonymous
2014-11-04
2019-05-29
  • Anonymous

    Anonymous - 2014-11-04

    I'd like to be able to output some text to a file (a debug log
    essentially). For some reason I am unable to on both my HTC One and my
    Samsung Galaxy tablet. Could someone post a small and simple snippet of
    code just so I can be sure I've understood the PDF manual correctly.

    I think it should be:
    open "O", #1, "testfile.txt"
    print #1; "test string"
    close #1

    Thank-you for any help.

     
  • Markus Hoffmann

    Markus Hoffmann - 2014-12-22

    Exactly that should do it. You should be able to read that file later again with

    open "I",#1,"testfile.txt"
    LINEINPUT #1,t$
    print t$
    close #1

     
  • Kevin

    Kevin - 2019-02-03

    Seems I'm having the same problem. After many tries, and some permutations, I cannot find a data file on my phone. I also cannot apparently read back data that I supposedly wrote.

    Here is an excerpt of my code dealing with this:

    OPEN "O",#1,"spl.dat"
    PRINT #1,"ABCD"
    PRINT #1,"EFGH"
    PRINT #1,"IJKL"
    PRINT #1,"MNOP"
    PRINT #1,"0"
    CLOSE #1
    PAUSE 1
    '
    x%=50
    y%=1350
    OPEN "I",#1,"spl.dat"
    more:
    INPUT #1,A$
    IF A$="0"
    goto done
    ENDIF
    text x%,y%,A$
    Y%=Y%=50
    goto more
    '
    done:
    showpage
    CLOSE #1
    PAUSE 5
    QUIT

    So when I've tried this, nothing at all appears on the screen. Very possible that this code is bad since I've changed it many times, but no errors. Maybe my phone is incompatible, but just looking for a little help if possible. Thanks! Kevin

     
  • Anonymous

    Anonymous - 2019-02-03

    The wrong line is the "Y%=X%=50", also Y%=1350 might well be outside of your screen, so you would not see any text.
    Maybe better simply use a PRINT a$ to show what you have read from the file.

    Have fun.

    ....Markus

     
  • Kevin

    Kevin - 2019-02-03

    Good catches! Thanks much! The test file now works, but I still cannot find that file on my phone, but it must be there somewhere.

     
  • Markus Hoffmann

    Markus Hoffmann - 2019-02-04

    Well,
    PRINT DIR$(0) should print you the current working directory.
    Thats where the files go.

     
  • Kevin

    Kevin - 2019-02-04

    Both the test and the in-work DAT files showed up last night. I know I had had some problems, and had to shut down my phone and re-power... maybe that's an explanation, not sure. But nice to know that I now have access to the file from outside X-11. Thanks again!

     
  • Kevin

    Kevin - 2019-02-07

    I continue to have problems with my Android phone when attempting to output data to a file. The problems can be locking up, showing the internal storage to be empty, displaying apps not selected, etc. , and sometimes can take several restarts to correct. I've alluded to it in a previous post mentioning that I had to rest my phone. Tow questions if I may...1) and I don't think this would explain my test file results, but in outputting to a file, is it necessary that all records be the same length? And 2) aside from different phone and Android variations, and run-awy programs, are there any other considerations to take into account that might cause these typees of problems?

    Thanks for anything you might be able to offer!

     
  • Anonymous

    Anonymous - 2019-02-07

    Well I am sorry, I do not know. I have not heard of this kind of problem so far. But ... who knows.
    1) no, not necessary. Maybe you want to have a look into the quite huge sample program collection: https://gitlab.com/kollo/X11-Basic_examples/tree/master many of them use the file functions.
    2) I do not know. I never faced these kind of problems with my devices (running rather old Android versions, however). Thats all I can tell.

     
  • Kevin

    Kevin - 2019-02-12

    Thought I'd correct a couple of typos and provide the snippet of code that is causing my problems.

    Typo #1: "I had to rest my phone" = I had to restart my phone.
    Typo #2: "Tow questions if I may" = Two questions if I may

    Here is the code segment:

    button_wait:
    MOUSEEVENT locx%
    locx%=mousex
    locy%=mousey
    'check each box
    FOR x%=1 to nbtns%
    gosub checkbox(bx%(x%),by%(x%),bx%(x%)+100,by%(x%)+50)
    IF inbox%=1
    pause .2
    a$=TIME$
    d$=DATE$
    hr$=LEFT$(a$,2)
    mn$=MID$(a$,4,2)
    a$=hr$+":"+mn$
    text bx%(x%)+10,by%(x%)+95,a$
    showpage
    '
    mo$=MID$(d$,4,2)
    day$=LEFT$(d$,2)
    '
    OPEN "A",#2,"spl.log"
    'log date, time, reason
    PRINT #2, mo$+"/"+day$+" "+a$+" "+label$(x%)
    CLOSE #2
    ENDIF
    NEXT x%

    This actually seems to work ok except for the problems it causes my phone.

    Thanks again for your input! -K

     
  • Kevin

    Kevin - 2019-02-20

    15 days seems a long time to wait for a response, although I'm not complaining.

    Hope all is OK with Markus.-Kevin

     
  • Markus Hoffmann

    Markus Hoffmann - 2019-05-29

    sorry, I forgot to log in. My post was anonymous.

     
  • Yet Another Troll

    Take a look at the stepdir.bas sample or my own take on it, which has yet to actually run to completion on my Android 5.1.1 phone. Newer Android versions could have gone even further down the everything-is-a-file philosophy rabbit hole and thus have even more hundreds of thousands of subdirectories in /proc, /dev, /sys, etc., so be patient, very patient.

    Program FindFiles
    
     Pattern$ = "*Scan*.PDF"
     PMFlags% = 16
    
     AllDirs$() = [ "d /" ]  ! Are you ready for adventure?
     Matches$() = [ "B0rk" ] ! Whatever comes our way?
     DirCount% = 1
     MatCount% = 0
     CurDir% = 0
    
     While CurDir% < DirCount%
    
      Clr P$, F$
      P$ = AllDirs$(CurDir%)
      Print CurDir%; " "; P$
      ' Pause 0.1
      S% = InStr(P$, " ")
      ' Print "FindFirst '"; Mid$(P$, S% + 1, Len(P$) - S%); ; "'"
    
      Clr F$
      On Error GoSub Mulligan ! We get one Mulligan per directory
      F$ = FSFirst$(Mid$(P$, S% + 1, Len(P$) - S%), "*", "dfa")
    
      If Len(F$) = 0 Then
       ! No-op
      Else If Left$(P$, 2) = "d " Then
       ! No-op
      Else If Left$(P$, 2) = "s " Then
       ! No-op
      Else
       Print "Weird dir "; P$; " contains files like "; F$
       Pause 5
      EndIf
    
      ' Discard the path's "d " or "s " prefix
      P$ = Mid$(P$, S% + 1, Len(P$) - S%)
    
      While Len(F$)
       S% = InStr(F$, " ")
       F$ = Left$(F$, S%) + P$ + Mid$(F$, S% + 1, Len(F$) - S%)
       ' Print F$
       ! Pause 0.1
    
       If Glob(F$, Pattern$, PMFlags%) Then
        Dim Matches$(MatCount% + 1)
        Matches$(MatCount%) = F$
        Inc MatCount%
        Print "Match "; MatCount%; " found "; F$
        Pause 5
       EndIf
    
       If (Left$(F$, 2) = "d ") Or (Left$(F$, 2) = "s ") Then
        ' Directory, or symbolic link to maybe a directory?
        ' Could following symlinks cause an infinite loop? How to detect?
        If DirCount% = UBound(AllDirs$()) Then
         Print "REDIM PRESERVE AllDirs$("; DirCount% + (DirCount% Div 4) + 8; ")"
         Dim AllDirs$(DirCount% + (DirCount% Div 4) + 8)
        EndIf
        AllDirs$(DirCount%) = F$ + "/"
        Inc DirCount%
       Else If Left$(F$, 2) = "- " Then
        ' Ordinary file
        ! No-op
       Else
        ' We found something new!
        Dim Matches$(MatCount% + 1)
        Matches$(MatCount%) = F$
        Inc MatCount%
        Print "Weird "; MatCount%; " found "; F$
        Pause 5
       EndIf
    
       Clr F$
       ' Is our Mulligan above still installed?
       F$ = FSNext$()
      Wend
      Inc CurDir%
     Wend
    
     Print DirCount%, MatCount%
     For i% = 0 To (MatCount% - 1)
      Print Matches$(i%)
     Next i%
    
     Print "OK"
    End
    
    Procedure Mulligan()
     E% = Err
     Print "B0rkage "; E%; " "; Err$(E%)
     Select E%
      Case -13 ! Permission denied
       ! No-op
      Case -33 ! File not found (symlink to missing file/dir?)
       ! No-op
      Case -20 ! Not a directory (symlink to ordinary file?)
       ! No-op
      Default
       Stop
     EndSelect
     ' Pause 0.5
     ' Resume Next
    Return
    
     
  • Yet Another Troll

    FOR THE LOVE OF GOD DO NOT FOLLOW SYMLINKS IN A FILESYSTEM WALKER!!1!

    This version actually halts eventually.

    Program DirWalkOnTheWildSide
    
     ' Can match all symbolic links with "s *" etc.
     Pattern$ = "*Basic*.PDF"
     PMFlags% = 16
    
     AllDirs$() = [ "d /" ]  ! Looking for adventure
     Matches$() = [ "B0rk" ] ! In whatever comes our way
     DirCount% = 1
     MatCount% = 0
     CurDir% = 0
    
     While CurDir% < DirCount%
    
      Clr P$, F$
      P$ = AllDirs$(CurDir%)
      Print CurDir%, "'"; P$; "'"
      ' Pause 0.1
      S% = InStr(P$, " ")
      ' Print "FindFirst '"; Mid$(P$, S% + 1, Len(P$) - S%); ; "'"
    
      Clr F$
      On Error GoSub Mulligan ! We get one Mulligan per directory
      F$ = FSFirst$(Mid$(P$, S% + 1, Len(P$) - S%), "*", "dfa")
    
      If Len(F$) = 0 Then
       ! No-op
      Else If Left$(P$, 2) = "d " Then
       ! No-op
      Else If Left$(P$, 2) = "s " Then
       ! No-op
      Else
       Print "Weird dir '"; P$; "' contains files like '"; F$; "'"
       Pause 5
      EndIf
    
      ' Discard the path's "d " or "s " prefix
      P$ = Mid$(P$, S% + 1, Len(P$) - S%)
    
      While Len(F$)
       S% = InStr(F$, " ")
       F$ = Left$(F$, S%) + P$ + Mid$(F$, S% + 1, Len(F$) - S%)
       ' Print "'"; F$; "'"
       ' Pause 0.1
    
       If Glob(F$, Pattern$, PMFlags%) Then
        Dim Matches$(MatCount% + 1)
        Matches$(MatCount%) = F$
        Inc MatCount%
        Print "Match "; MatCount%; " found '"; F$; "'"
        ' Pause 5
       EndIf
    
       If (Left$(F$, 2) = "d ") ! Or (Left$(F$, 2) = "s ") Then
        ' Directory, or symbolic link to maybe a directory?
        ' Could following symlinks cause an infinite loop? How to detect?
        If DirCount% = UBound(AllDirs$()) Then
         ' Hundreds of thousands of subdirectories!!!1!
         Print "REDIM PRESERVE AllDirs$("; DirCount% + (DirCount% Div 8) + 4; ")"
         Dim AllDirs$(DirCount% + (DirCount% Div 8) + 4)
        EndIf
        AllDirs$(DirCount%) = F$ + "/"
        Inc DirCount%
       Else If (Left$(F$, 2) = "- ") Or (Left$(F$, 2) = "s ") Then
        ' Ordinary file (or symlink into who knows where)
        ! No-op
       Else
        ' We found something new!
        Dim Matches$(MatCount% + 1)
        Matches$(MatCount%) = F$
        Inc MatCount%
        Print "Weird "; MatCount%; '" found "; F$; "'"
        Pause 5
       EndIf
    
       Clr F$
       ' If we get here, our Mulligan above should still be installed
       F$ = FSNext$()
      Wend
      Inc CurDir%
     Wend
    
     Print UBound(AllDirs$()), DirCount%, MatCount%
     For i% = 0 To (MatCount% - 1) ! Needs parens or it's a syntax error
      Print i%, "'"; Matches$(i%); "'"
     Next i%
     Print MatCount%; " match(es) found."
    
     Print "OK"
    End
    
    Procedure Mulligan()
     E% = Err
     Print "B0rkage "; E%; " "; Err$(E%)
     Select E%
      Case -13 ! Permission denied
       ! No-op
      Case -33 ! File not found (symlink to missing file/dir?)
       ! No-op
      Case -20 ! Not a directory (symlink to ordinary file?)
       ! No-op
      Default
       Stop
     EndSelect
     ' Pause 0.5
     ' Resume Next
    Return
    
     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.