Hi
CharlesRattletail
Const NULL_PTR = 0^ is there to force the const to be a 8bit LongLong. I consider this to be good practice particularly when working with the win32 api.
Some api functions expect\return LongLong values.
As an example, the SetWindowPos api expects a HWND in its second (hWndInsertAfter) argument... The C\C++ HWND data type translates into an 8bit LongLong in x64bit excel.
Although in this case, passing just
0 or
0& will still work and will evaluate to LongLong in x64bit excel, I prefer to use the correct data type NULL_PTR for consistency and cleaner code.
In VBA5/VBA6 ( Excel 2007 or ealier) , the LongPtr *data type* doesn't exist. Therefore, if the code happens to be running in VBA5/VBA6 , LongPtr will not compile... But since we are defining LongPtr as an Enum, it will be a valid type, evaluating to Long since Enums are internally defined by VB as Long.
Now, the reason for doing this is to save you the hassle to use conditional compilation repeatedly througouht the code each time LongPtr is encountered... So, using this Enum trick will substantially reduce the number of conditional compilations needed in the code particularly if the code is large and there are many instances of LongPtr. This will also reduce the chances of making data type mistakes ( 4bit Long vs 8bit LongPtr in excel x64bit)
BTW, it is worth remembering that LongPtr is not in fact a true data type. it translates into either Long or LongLong depending on the process bitness.
Yes. That was my mistake. It should have been
Dim Pos(1&) As Long ... Lucky it worked here.
Adding the & type declaration character is just a habit I got into to coerce litteral numbers into Longs . In this case, using Pos(2) or Pos(2&) won't make any difference as array indexes are of signed 32bit longs ... Note that we are talking here about data type of array
indexes not about data type of array data (content) which can be of any type.