Reading a .txt - File

Just starting out? Need help? Post your questions and find answers here.
Softdrink97
Posts: 2
Joined: Mon Nov 06, 2017 11:25 am

Reading a .txt - File

Post by Softdrink97 »

Hello there,
i just started with Spiderbasic. My Problem: I have Example.txt File with the Syntax : 890, 1000, 1100, 935,....
I want to start read the data into a array or a list. I dont know how to seperate the data with the "," as a Split Char. The Debug ReadString shows me the whole Data in the Debug Window, but again i dont know how to split the data and wirte them into a array or list.
(In the end i want a live version of reading the data but that is far away :D)
Here you see my code until now:

Code: Select all

ExamineDesktops()


Procedure DateiEinlesen(Status, Filename$, File, Size)
  
  CloseWindow(0)
  If Status = #PB_Status_Loaded
    Debug "File: " + Filename$ + " - Size: " + Size + " bytes"
    Debug "Reading first 100 lines:"
    
    
    
    NewList MyList()
    
    While Eof(0) = 0 And NbLine < 100 ;Die ersten 100 Lines werden ausgelesen
      Debug ReadString(0)
      
               
           
         NbLine+1
    Wend
    
    CloseFile(0)
    OpenWindow(0, 0, 0, 1280, 875, "MittigesFenster")
    
  ElseIf Status = #PB_Status_Error
    Debug "Error when loading the file: " + Filename$
  EndIf
EndProcedure

Procedure DieDateiLesen()
  If NextSelectedFile()
    ReadFile(0, SelectedFileID(), @DateiEinlesen(), #PB_LocalFile)
  EndIf  
EndProcedure

Procedure ChooseFileEvent()
  OpenFileRequester("text/plain",@DieDateiLesen())
EndProcedure



OpenWindow(0, 0, 0, 300, 50, "Read file example", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose a text file...")
BindGadgetEvent(0, @ChooseFileEvent())
Softdrink97
Posts: 2
Joined: Mon Nov 06, 2017 11:25 am

Re: Reading a .txt - File

Post by Softdrink97 »

Oh wow I am stupid. :roll:
Thank for the answer Sir :)
Post Reply