none
Small Basic error RRS feed

  • Question

  • I am having an error with a peice of code I wrote.

    This is a custom program for uploading programs from my PC to my new server (at the moment my server is down so it goes to my google drive).

    I keep getting this error when I try to run it:    at Microsoft.SmallBasic.Library.File.CopyFile(Primitive sourceFilePath, Primitive destinationFilePath)
       at _SmallBasicProgram._Main()

    here is the code:

    location = "C:\Users\realC\Google Drive\Programs\Small Basic\Nsync\Nsync Tasks.txt"
    location2 = "C:\Users\realC\Google Drive\Programs\Small Basic\Nsync\Nsync Task Propertys.txt"
    TextWindow.ForegroundColor = "green"
    TextWindow.WriteLine("NSync")
    TextWindow.WriteLine("Made by the Foxstrike Corperation")
    Program.Delay(1000)
    TextWindow.WriteLine("loading...")
    Program.Delay(1000)
    fileCheck = File.ReadLine(location,1)
    TextWindow.WriteLine("Ready...")
    If fileCheck = 0 Then
      TextWindow.WriteLine("0 Files ready for upload")
    EndIf
    CheckForUpload:
    While "True"
      If (File.ReadLine(location,1)) = 1 Or (File.ReadLine(location,1)) > 1 Then
        Goto Upload
      EndIf
    EndWhile
    Upload:
    TextWindow.WriteLine("Working...")
    Task = File.ReadLine(location2,1)
    Program.Delay(1000)
    TextWindow.WriteLine("Uploading...")
    TaskOut = File.ReadLine(location,2)
    File.CopyFile(Task,TaskOut)
    File.WriteLine(location2,1,"")
    File.WriteLine(location2,2,"")
    Program.Delay(1000)
    TextWindow.WriteLine("Upload Compleate")
    Goto CheckForUpload

    I don't know if there is an error with my code or small basic.

    Tuesday, June 18, 2019 2:58 PM

Answers

  • I've changed your program. It needs only one file with an even numer of lines, first, third .... filennem yo upload,

    second, fourth ...  the destination. The program stops when all line are read:

    DIR=Program.Directory+"\"
    location2=DIR+"filelist.txt"
    
    TextWindow.ForegroundColor = "green"
    TextWindow.WriteLine("NSync")
    TextWindow.WriteLine("Made by the Foxstrike Corperation")
    Program.Delay(1000)
    TextWindow.WriteLine("loading...")
    Program.Delay(1000)
    
    TextWindow.WriteLine("Working...")
    
    Task = File.ReadLine(location2,1)
    TaskOut = File.ReadLine(location2,2)
    line=3
    Program.Delay(1000)
    While Text.GetLength(Task)>5
      TextWindow.WriteLine("Uploading..."+Task+">>>"+Taskout)
      File.CopyFile(Task,TaskOut)
      Program.Delay(1000)
      Task = File.ReadLine(location2,line)
      TaskOut = File.ReadLine(location2,line+1)
      line=line+2
    EndWhile
    


    Jan [ WhTurner ] The Netherlands

    Tuesday, June 18, 2019 5:59 PM
    Answerer

All replies

  • When I make a file "Task.txt" in my directory with on the firstt line a "1" and make location pointing to this file, I get no error message. As I didn't know the contents of location2, I can't test more., but the progran keep looping the upload message.

    Are you using  "Small Basic Prime"? This has a good dubugging part, so you can see what generates the error, by stepping through the code


    Jan [ WhTurner ] The Netherlands


    Tuesday, June 18, 2019 3:23 PM
    Answerer
  • i don't have it but i will check your fix and see if it works.
    Tuesday, June 18, 2019 3:34 PM
  • location 2 contains 2 directorys:

    1. where the file is

    2. where to copy the file too

    Tuesday, June 18, 2019 3:35 PM
  • here is the contence of the file:

    C:\Users\Public\Documents\Code.txt
    C:\Users\Public\Documents\bin

    I am using them to test the program and if it works.

    Tuesday, June 18, 2019 3:37 PM
  • I changed the names to my filesytem,

    DIR=Program.Directory+"\"
    location=DIR+"Task.txt"
    location2=DIR+"filelist.txt"

    put in "filielist" two filenames (original and a non-existing name) and tried to run.

    Then I discovered that in the line   TaskOut = File.ReadLine(location,2) the nmae should be location2 (two) and it worked,  In all the testing I never got an errormessage

    Your program errases the first two lines in the location2 file and then keeps reading these empty lines. This is probably not what you want.


    Jan [ WhTurner ] The Netherlands

    Tuesday, June 18, 2019 4:29 PM
    Answerer
  • I've changed your program. It needs only one file with an even numer of lines, first, third .... filennem yo upload,

    second, fourth ...  the destination. The program stops when all line are read:

    DIR=Program.Directory+"\"
    location2=DIR+"filelist.txt"
    
    TextWindow.ForegroundColor = "green"
    TextWindow.WriteLine("NSync")
    TextWindow.WriteLine("Made by the Foxstrike Corperation")
    Program.Delay(1000)
    TextWindow.WriteLine("loading...")
    Program.Delay(1000)
    
    TextWindow.WriteLine("Working...")
    
    Task = File.ReadLine(location2,1)
    TaskOut = File.ReadLine(location2,2)
    line=3
    Program.Delay(1000)
    While Text.GetLength(Task)>5
      TextWindow.WriteLine("Uploading..."+Task+">>>"+Taskout)
      File.CopyFile(Task,TaskOut)
      Program.Delay(1000)
      Task = File.ReadLine(location2,line)
      TaskOut = File.ReadLine(location2,line+1)
      line=line+2
    EndWhile
    


    Jan [ WhTurner ] The Netherlands

    Tuesday, June 18, 2019 5:59 PM
    Answerer
  • thanks for the help!

    it fully works as expected!

    Wednesday, June 19, 2019 7:33 AM