2012-01-16 50 views
3

我試圖將舊的Quick BASIC程序轉換爲VB.Net。似乎沒有任何直接替換舊的文件語句。建立一個數據庫似乎對我的簡單需求是過度殺傷性的。將Quick BASIC轉換爲VB.Net - 隨機訪問文件

如何在VB.Net中執行以下操作?

OPEN "test.dat" FOR RANDOM AS #1 LEN = 20 
FIELD #1, 10 AS a$, 10 AS b$ 
LSET a$ = "One" 
LSET b$ = "Two" 
PUT #1, 1 
GET #1, 1 
PRINT a$, b$ 
CLOSE #1 

回答

7

Microsoft.VisualBasic.FileOpenFilePutFileGet語句應該是上面的大部分代碼十分直接的替代品。

Microsoft.VisualBasic.FileOpen(1, "test.dat", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Shared) 

    Dim output As New Fields 

    output.A = "One" 
    output.B = "Two" 

    Microsoft.VisualBasic.FilePut(1, output, 1) 

    Dim input As New Fields 

    Microsoft.VisualBasic.FileGet(1, input, 1) 

    Debug.WriteLine("A = " & input.A & "; B = " & input.B) 

    FileClose(1) 
+0

FIELD#1,10,爲$ 10爲B $ 如何更換本例中的FIELD語句? – Lexib0y