我有一本excel工作簿。下面的代码可以在32位窗口上运行,但不能在64位窗口上运行。
Private Function wwGetMD5HashPart(ByRef rngData As Range, ByRef lcellCounter As Long, ByRef hhash As Long) As Long
Dim ocell As Range
Dim vValue As Variant
Dim lresult As Long
On Error GoTo E1
'Fill it with the contents of the range
For Each ocell In rngData.Cells
lcellCounter = lcellCounter + 1
If Not IsEmpty(ocell.Value) Then
vValue = CStr(ocell.Value) 'rasey o40611
Else
' must use a value for the empty cell not at all likely to be used be accident.
vValue = "^ " & CStr(lcellCounter) 'rasey 040611
End If 'rasey 040611
lresult = CryptHashData(hhash, StrPtr(vValue), LenB(vValue), 0&) 'rasey 040611
Next
wwGetMD5HashPart = lresult
Exit Function
E1: If gbDebug Then
MsgBox "Error in wwGetMD5HashPart"
Stop
End If
End Function
我收到编译错误:输入不匹配
答案 0 :(得分:1)
请参阅http://msdn.microsoft.com/en-us/library/office/gg264421%28v=office.15%29.aspx
运行64位时,使用 Long 数据类型长。它决定它的32位还是64位,以及是使用Long还是LongLong。
注意:如果在VB6上运行,这将会中断。因为它不包含LongPtr数据类型。为了在两者上运行,你必须使用编译时间。
#If Vba7 Then
'Decalre PtrSafe Sub
'Change all Longs to LongPtr
#Else
'Keep as is
#EndIf
旁注:如果同时运行,请注意以下
psudo:
int x = long b 'Works on VB6
对于VB7,必须将其更改为:
int x = Cint(long b)