![]() |
|
#28
|
||||
|
||||
|
Quote:
![]() And yes, I agree, its a good idea to set objects to nothing earlier if you don't need them anymore... but if you are already at the end of the sub then... yep, we agree on that. Quote:
![]() Quote:
The memory image is in a format called little endian. Intel-based systems store bytes little end first so the least significant byte is on the left. You have to flip the bytes to see the true hex value... If you look at the last section of getReference2() in my previous post you will see how that I move the contents of the local pointer (the address of Sheet1) into another LongPtr type called objwksPtr. I can then print out the hex value of that pointer and VBA will interpret it correctly. Code:
01 Sheet1 : Address: 0x1D6DA618 : Contents: 0xC0EA4C18 using objPtr
02 objwks : Address: 0x002AEF90 : Contents: 0x00000000 using varPtr, set to Nothing
03 objwks : Address: 0x1D6DA618 : Contents: 0xC0EA4C18 using objPtr
04 objwks : Address: 0x002AEF90 : Contents: 0x18A66D1D using varPtr
05 objwks points to: 0x1D6DA618
Line 04 is from this...
' Using varPtr, can diferentiate.
' The local Worksheet Object is treated as a reference, not an Object: the reference is not resolved
lptr = VarPtr(objwks): objName = "objwks "
Debug.Print PointerToSomething(objName, lptr, coBytes) & vbTab & "using varPtr"
It produces this image of the contents of the objwks reference
0x18A66D1D
Line 05 is from this
' The contents of the local variable (objwks) is the address of the global object but byte-reversed (little endian)
' Load the reference into a LongPtr type and read back the byte-corrected (big endian) value of the reference
Mem_Copy objwksPtr, ByVal VarPtr(objwks), PTR_LENGTH
Debug.Print objName & vbTab & "points to: " & "0x" & HexPtr(objwksPtr)
It produces this image of the contents of the objwks reference
0x1D6DA618
And this is the correct address of the Sheet1 Object
But in fact they are the same number but in different formats...
1D6DA618 18A66D1D
Ive also attached a couple of pics to try to make it clear... |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wierd "script code" in a downloaded .doc file | CNBarnes | Word | 2 | 10-18-2012 02:07 AM |
replace data from variable with "sub and super script" from excel to word by vba
|
krishnaoptif | Word VBA | 9 | 06-22-2012 05:08 AM |
How to choose a "List" for certain "Heading" from "Modify" tool?
|
Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |
| Rules and Alerts: "run a script"? | discountvc | Outlook | 0 | 06-15-2010 07:36 AM |
| An "error has occurred in the script on this page" | decann | Outlook | 8 | 09-03-2009 08:54 AM |