< Gambas

Back to Gambas

File handling

Please refer to the official wiki: http://gambaswiki.org/wiki/lang/open

You can read a file with some text for example.

With Gambas 1

  ' Gambas 1
  Dim OneLine As String
  Dim FileName As String = "/home/moi/test.txt"
  Dim hFile As File

  OPEN FileName FOR READ AS #hFile
  WHILE NOT Eof(hFile)
    LINE INPUT #hFile, OneLine
    PRINT OneLine
  WEND
  CLOSE #hFile

It's a bit easier with Gambas 3.

 ' Gambas 3
  Dim hFile As File
  Dim OneLine As String
  Dim FileName As String = "/home/moi/test.txt"

  hFile = Open FileName For Read
  While Not Eof(hFile)
    Line Input #hFile, OneLine
    Label1.Text = OneLine
  Wend
  Close #hFile
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.