none
Can Small Basic make a txt file and then save it? RRS feed

  • Question

  • how do i create a txt file using small basic and then save it in a directory?

    chase morell

    Saturday, March 2, 2013 3:10 PM

Answers

  • There are many ways!  :D

    For now, here's a sample I had laying around here.

    It saves and reloads an array from disk:

    ' Save Array File Example
    ' by GoToLoop (2013/Jan)
    
    ' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
    '/thread/1429cf95-e0c9-44d3-9529-400908154495
    
    PATH = Program.Directory+"\Data\"
    NAME = "Test"
    EXT  = ".txt"
    
    LF = Text.GetCharacter(10) ' <- Line-feed special ASCII code
    
    TextWindow.WriteLine(PATH+NAME+EXT+LF) ' <- Display full path
    
    ' Create text array to save it later
    myFile[1] = "Jak, ic wot priyede in my faire face;" + LF
    myFile[2] = "He thout me full worly, so have I good grace." + LF
    myFile[3] = "As we turnden oure daunce in a narrowe place," + LF
    myFile[4] = "Jak bed me the mouth, a kussinge ther was-" + LF
    myFile[5] = "Thout I on no gile." + LF
    
    File.CreateDirectory(PATH) ' <- Create Folder/Directory
    File.WriteContents(PATH+NAME+EXT, myFile) ' <- Save the text array
    
    myFile = "" ' <- Clear myFile text array
    
    myFile = File.ReadContents(PATH+NAME+EXT) ' <- Reload it into myFile
    TextWindow.WriteLine(myFile) ' <- Proof that myFile was loaded from disk!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Saturday, March 2, 2013 3:17 PM
    Answerer

All replies

  • There are many ways!  :D

    For now, here's a sample I had laying around here.

    It saves and reloads an array from disk:

    ' Save Array File Example
    ' by GoToLoop (2013/Jan)
    
    ' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
    '/thread/1429cf95-e0c9-44d3-9529-400908154495
    
    PATH = Program.Directory+"\Data\"
    NAME = "Test"
    EXT  = ".txt"
    
    LF = Text.GetCharacter(10) ' <- Line-feed special ASCII code
    
    TextWindow.WriteLine(PATH+NAME+EXT+LF) ' <- Display full path
    
    ' Create text array to save it later
    myFile[1] = "Jak, ic wot priyede in my faire face;" + LF
    myFile[2] = "He thout me full worly, so have I good grace." + LF
    myFile[3] = "As we turnden oure daunce in a narrowe place," + LF
    myFile[4] = "Jak bed me the mouth, a kussinge ther was-" + LF
    myFile[5] = "Thout I on no gile." + LF
    
    File.CreateDirectory(PATH) ' <- Create Folder/Directory
    File.WriteContents(PATH+NAME+EXT, myFile) ' <- Save the text array
    
    myFile = "" ' <- Clear myFile text array
    
    myFile = File.ReadContents(PATH+NAME+EXT) ' <- Reload it into myFile
    TextWindow.WriteLine(myFile) ' <- Proof that myFile was loaded from disk!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Saturday, March 2, 2013 3:17 PM
    Answerer
  • Look for the subcommands of the File command (WriteLine, WriteContents, AppendContents)

    Jan [ WhTurner ] The Netherlands

    Saturday, March 2, 2013 3:19 PM
    Answerer