Announcement

Collapse
No announcement yet.

Read a Text file?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read a Text file?

    I want to read a small text file from the uSD using the following code, but I will only get one line with unreadable characters. What I'm doing wrong?

    HTML Code:
    var iFile;          //File Handle
    var Filename[20];   //string that holds the filename
    var InfoFile[500];  //buffer for the file content
    
    
    func DisplayInfofile()
    var szL;
    var szH;
    
    to(Filename);print("M",[STR] ObjInfo1,".txt");    //saves the filename to array   "M1.txt"
    print([STR] Filename);                            //Debug print the filename 
    if(file_Exists(Filename))                         //check if file exists
    gfx_Cls();                                   
    iFile:= file_Open(Filename, 'r');               //Open File for reading
    file_Size(iFile, &szH, &szL);                    //get Filesize
    file_Read(InfoFile, szL, iFile);                // Read the file fo buffer
    
    txt_Set(FONT_SIZE,FONT1);                       //Set font
    txt_MoveCursor(1,1);                            //got top left corner 
    print([STR] InfoFile);                          //Print the buffer to screen
    k:=-1;                                          
    repeat
    k:=readcom();                                 //repeat until any key pressed  
    until (k!=-1);
    gfx_Cls();
    endif
    endfunc
    Attached files M1.txt (206 B)

  • #2


    Ok, the problem is solved. My text file had wrong format. I used UltraEdit to set the format to Unix instead of DOS and the all worked fine.

    Comment


    • #3


      Great
      Atilla

      Comment

      Working...
      X