Even though class modules in VBA are not as powerful as their brethren in C++, C#, or VB.NET, I'm still a fan. Some time ago,
Windows 7 X86, I wrote an application which contained a class called ISearch and then subclasses which implemented this class using the Implements keyword. For debugging, I thought it would be cool to print the address of the ISearch implementation object using the ObjPtr function. The ObjPtr function returns a Long that represents the memory address of an object variable. These numbers were a bit long for my liking, so to make them easier to read and understand,
Windows 7 Home Basic, I wrote this function called FormatHex. This function wraps the Hex function in VBA but applies some formatting to it.
' -------------------------------------------------------------------------
' Function : FormatHex
' Purpose : Formats a number in hexadecimal format
' Arguments: lngValue - numeric value to format
' : nLength - returned length of the string
' : strPrefix - hex prefix for the number - defaults to 0x
' -------------------------------------------------------------------------
Public Function FormatHex(lngValue As Long,
Office 2007 Activation, _
Optional nLength As Byte = 8, _
Optional strPrefix As String = "0x") As String
FormatHex = Trim(strPrefix & Replace(Format(Hex(lngValue),
Cheap Windows 7, String(nLength, "@")), " ",
Buy Office 2010, "0"))
End Function
<div