32位办公环境vba应用中uint64值的检索

Retrieving a uint64 value in a vba application running 32 bit office

本文关键字:uint64 检索 应用 环境 vba 32位      更新时间:2023-10-16

我有一些vba编码,用于以二进制模式打开文件并将值存储到变量以供后续使用。我有关于文件结构的信息(我认为这些文件是用C或c++开发的程序创建的),所以知道文件中位置的偏移量,它的数据类型是Uint64(所以8字节)。

代码片段如下:

Dim strFile as String
Dim p as Long
strFile = "Testfile"
Open strFile For Binary As #1    ' Open file.
p = 1024 ' position of variable in file
Get 1, p, Value

变量'Value'需要声明为相当于Unit64的VBA,但由于我运行的是32位版本的office,我有点卡住了。我试图声明为Double,但这没有返回正确的值。不知道为什么。

如有任何建议,不胜感激

谢谢

整数数组可能是最好的选择。

Sub TestGetBin()
    Dim DataByte(0 To 7) As Byte
    Dim DataLong(0 To 1) As Long
    Dim i As Long
    ' File contains "abcdefghijklmnopq"
    Open "D:abc.txt" For Binary As #1
    Get 1, 1, DataByte
    Get 1, 1, DataLong
    Debug.Print Hex(DataLong(0)), Hex(DataLong(1))
    For i = 0 To 7
        Debug.Print Hex(DataByte(i))
    Next i
    Close #1
End Sub

这个收益率

64636261      68676665
61
62
63
64
65
66
67
68

所以你可能会更喜欢字节数组(并从它创建你的数字)。
(嗯,这取决于号码是如何存储的。