Closed SanbiVN closed 1 year ago
Hi @SanbiVN ,
I was fine using the:
#If VBA7 = 0 Then
Private Enum LongPtr
[_]
End Enum
#End If
trick because I only want to avoid many #If
declarations for VBA6 because my target is VBA7 to be honest. Moreover, LongPtr
already suggests that it's Long
on x32. However, I dislike the fact that under the Locals window (while debugging) you still see the data type as LongPtr
when using such an enum declaration. Again, not a big deal for me as I target VBA7.
In VBA7 I am 100% against showing a data type called LongLong
which is actually Long
. It's ambiguous, not clean and most of all misleading.
Hi @Cristianbuse!
I understand the goal of declaring Enum LongPtr and LongLong, is to make the declaration in code more concise, but cross-platform compatible. As you said, in the code, the declarations are LongLong so it would make more sense to replace all of them to LongPtr, right?
Hi @Cristianbuse! I'm so sorry, I carelessly forgot to translate into your language
Hi @SanbiVN ,
As you said, in the code, the declarations are LongLong so it would make more sense to replace all of them to LongPtr, right?
Yes and no. 😄. Sometimes, you really want to directly check for x64 and write code that is specific to x64 only. In that case there is no need to go through the extra step of using LongPtr
- example here.
In your example (the InitByAddress
method in this repo) you are correct, I could just use LongPtr
😄. But would still not declare a LongLong
enum.
However, since I declared the LongPtr
enum as private, I cannot use it for the InitByAddress
method wich is Public. So, I could have used what I already have, which is this:
#If Win64 Then
Public Sub InitByAddress(ByVal memAddress As LongLong, Optional ByVal argText As String)
#Else
Public Sub InitByAddress(ByVal memAddress As Long, Optional ByVal argText As String)
#End If
End Sub
or simply this:
#If VBA7 Then
Public Sub InitByAddress(ByVal memAddress As LongPtr, Optional ByVal argText As String)
#Else
Public Sub InitByAddress(ByVal memAddress As Long, Optional ByVal argText As String)
#End If
End Sub
They would both work fine. Thanks for your feedback.
Hi @cristianbuse! I got it. You explained the problem very clearly
hi @cristianbuse Can you explain me, why not declare Enum LongLong compatibility. To write more compact code as below. Is there an overhead during code compilation?
Code in your class module:
Why can't it be like this:
I don't mean just in your project, but maybe bigger projects!