vb6读写二进制文件

vb6读写二进制文件,vb6,Vb6,我试图使一个项目,可以让我从一个特定的二进制文件读取,并从文件中的特定偏移量 我发现以下代码没有主源: Sub GetData() Dim nFileNum As Integer, sLocation1 As String, sLocation2 As String 'declarations nFileNum = FreeFile 'get file ID Open App.Path & "\Hologram.bin" For Binary Access Read

我试图使一个项目,可以让我从一个特定的二进制文件读取,并从文件中的特定偏移量

我发现以下代码没有主源:

Sub GetData()
Dim nFileNum As Integer, sLocation1 As String, sLocation2 As String 'declarations
nFileNum = FreeFile 'get file ID
Open App.Path & "\Hologram.bin" For Binary Access Read Lock Read Write As #nFileNum 'file to open
sLocation1 = Space$(10) 'my first offset is 10 chars long, set a string placeholder must equal the size of data you want to hold
sLocation2 = Space$(32) 'my second offset is 32 chars longs, set a string placeholder must equal the size of data you want to hold
Get #nFileNum, 12000, sLocation1 'The offset location in Binary of the data I want to show (+1 to offset because we start at 0!)
Text1.Text = sLocation1  'display the 10 chars data in a textbox
Get #nFileNum, 12500, sLoation2 ' The offset location in Binary of the data I want to show (+1 to offset because we start at 0!)
Text2.Text = sLocation2  'display the 32 chars data in a textbox
Close #nFileNum  'Cloase the file
End Sub  'Call GetData()

Sub WriteBin()
Dim sFileText As String 'declarations
Dim iFileNo As Integer
iFileNo = FreeFile
Dim nFileNum As Integer
nFileNum = FreeFile 'get random file number
Open App.Path & "filename.bin" For Binary Access Write Lock Read Write As #nFileNum 'open file for edit
Put #nFileNum, 12000, Text1.Text 'Offset is +1 because we start at 0! write data from textbox1 to offset location
Put #nFileNum, 12500, Text2.Text 'Offset is +1 because we start at 0! write data from textbox2 to offset location
Close #nFileNum 'Call WriteBin()
End Sub
我想找到这段代码的其余部分,以便使用它。
感谢

GetData
展示了实现所需功能的机制。它打开一个二进制文件,从2个特定位置读取数据,显示数据并关闭文件
GetData
将从代码中的其他位置调用。您具体在寻找什么?您好,上面的代码以二进制形式加载文件,并在文本框字段中显示加载文件的给定偏移量。这个想法是能够读取偏移量,然后能够改变它。但是我得到了一个语法错误,某种溢出错误。如果我给的偏移量是10,这是可行的,但是如果我给的偏移量是6D9711,那么我会得到错误。thanksA溢出不是语法错误,而是运行时错误。向我们显示准确的错误消息、它指向的代码行以及该代码行中涉及的变量使用的值。这里有一个很长的机会:你提到了十六进制。您是否正确地在它们前面加上
&H
,例如
&H6D9711
,以便VB可以将它们解释为十六进制数?Hello Hell,谢谢您向我指出&H,我正在通过将其转换为块来更正此问题,但按照您的建议,ad&H要容易得多。现在我唯一的问题是不是所有的文件都有相同的偏移量。例如,从10.bin文件中,有些文件具有相同的精确偏移量,而其他文件则没有。我正在处理的.bin文件上有文本。所以我的想法是在我的项目中逐个加载它们,这样我就可以更改它们的显示文本。这些.bin文件的文本显示在我的全息图显示中,我发现这是编辑它们最简单的方法。我想知道是否可以添加一种方法来搜索文件中指定的十六进制名称。例如:4E 61 6D 65。