跳轉至正文

Gambas/檔案

來自維客圖書,開放世界中的開放書籍

返回 Gambas

檔案操作

[編輯 | 編輯原始碼]

請參閱官方 wiki:http://gambaswiki.org/wiki/lang/open

例如,你可以閱讀一些文字檔案。

使用 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

使用 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
華夏公益教科書