Converting Quick BASIC to VB.Net - Random Access Files

我是研究僧i 提交于 2019-12-22 09:31:05

问题


I'm trying to convert an old Quick BASIC program to VB.Net. There doesn't appear to be any direct replacement for the old file statements. Building a database seems like overkill for my simple needs.

How can I do the following in 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:


The Microsoft.VisualBasic.FileOpen, FilePut, and FileGet statements should be pretty direct replacements for most of your code above.

    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)


来源:https://stackoverflow.com/questions/8886096/converting-quick-basic-to-vb-net-random-access-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!