将Quick BASIC转换为VB.Net - 随机访问文件

时间:2012-01-16 20:50:52

标签: vb.net file random-access qbasic

我试图将旧的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

1 个答案:

答案 0 :(得分: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)