Reputation: 2654
I have an excel workbook. the following piece of code works on 32 bit windows but not on 64 bit windows.
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
I get a compile error: type mismatch
Upvotes: 0
Views: 489
Reputation: 122
See http://msdn.microsoft.com/en-us/library/office/gg264421%28v=office.15%29.aspx
Use the LongPtr data type for Long when running 64bit. It decides if its 32 or 64 bit, and whether to use Long or LongLong.
Note: this will will break if running on VB6. As it does not contain the LongPtr data type. In order to run on both you will have to use a compile time if.
#If Vba7 Then
'Decalre PtrSafe Sub
'Change all Longs to LongPtr
#Else
'Keep as is
#EndIf
Side Note: If running on both watch out for the following
psudo:
int x = long b 'Works on VB6
For VB7 have to change it to:
int x = Cint(long b)
Upvotes: 1