Web development India freelance website designer developer India SEO

Convert API constant Hex formats into VB-friendly Hex values

When you view API function documentation, you'll often see function constant values represented like so:

#define URL_ESCAPE_UNSAFE 0x20000000

In this expression, the constant's name, URL_ESCAPE_UNSAFE, is followed by the Hex value, 0x20000000. In VB, of
course, this declaration might look something like the following:

Private Const URL_ESCAPE_UNSAFE As Long = 0x20000000

However, Visual Basic won't recognize the 0x20000000 format. As a result, you'll need to convert these kinds of values
into either VB Hex format or their decimal value.

As you may know, the 0x portion of any Hex value is really just a notation to signify that the value is in Hex, as opposed to
regular Decimal or other number format. In VB, to indicate a Hex value you precede it with &H. With this in mind,

0x20000000

becomes

&H20000000

As a result, the previous constant declaration would look as follows in VB

Private Const URL_ESCAPE_UNSAFE As Long = &H20000000

When you declare an API constant, however, you can also use a standard decimal value, if you so choose. Believe it or
not, to quickly convert a Hex value into its decimal equivalent, you can use Windows own built-in Calculator.

To see what we mean, launch the Calculator application. Next, select View | Scientific from the menubar. When you do,
the calculator expands to include a host of scientific functions. Near the top, it also lets you choose the format in which
you wish to view the numbers, Hex and Dec included. By entering a Hex number into the entry field and then selecting the
Dec option, we can quickly convert from one format to the next.

For example, in the Calculator select the Hec option, and then enter 2000000. Now, switch to Dec. When you do the
calculator displays the number 33554432. You can then use this number as the value of the API function constant, like so:

Private Const URL_ESCAPE_UNSAFE As Long = 33554432
Convert API constant Hex formats

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

India web developer web development India | India web development company India ecommerce web developer