From: Irfan S. Fazli on
I have noticed that when:
sVar = hex$(a byte value) ' value is within 0..255
debug.print Format$(sVar, "00")

if the value of sVar is like 1a, 2a, 3a, 4a, ... 9a the return value is "00",
while if it is any other hex value, it is properly returned.
Can anyone please explain me if it some problem with Format() function and
its workaround.
--
IRFAN.

From: Steve on
On Jun 16, 6:35 am, Irfan S. Fazli
<IrfanSFa...(a)discussions.microsoft.com> wrote:
> I have noticed that when:
>    sVar = hex$(a byte value)  ' value is within 0..255
>    debug.print Format$(sVar, "00")        
>
> if the value of sVar is like 1a, 2a, 3a, 4a, ... 9a the return value is "00",
> while if it is any other hex value, it is properly returned.
> Can anyone please explain me if it some problem with Format() function and
> its workaround.
> --
> IRFAN.

I imagine you will find that any "hex" value which has an alpha
character in it will result in "00". This is because the Format$
function is seeing the value in the first argument as a string (not a
number).
Try
sVar = hex$(a byte value) ' value is within 0..255
Debug.Print Format("&H" & sVar, "00")
which will force the function to evaluate the first arg as a hex
number.

The solution provided above borders on rediculous though a cleaner
solution might be to drop the conversion of the byte value to hex ie.
sVar = a_byte_value ' value is within 0..255
Debug.Print Format(sVar, "00")
Then we do not have to convice the Format$ function that the first
argument is in fact a number.

However I suspect what you are actually trying to do is simply display
the hex notation of the byte value.
In this case your code should simply be:
sVar = hex$(a byte value) ' value is within 0..255
Debug.Print sVar

Hope this helps,
Steve
From: Helmut Meukel on
"Irfan S. Fazli" <IrfanSFazli(a)discussions.microsoft.com> schrieb im Newsbeitrag
news:A010DF97-2B14-4D59-AC35-11F3C159EB71(a)microsoft.com...
>I have noticed that when:
> sVar = hex$(a byte value) ' value is within 0..255
> debug.print Format$(sVar, "00")
>
> if the value of sVar is like 1a, 2a, 3a, 4a, ... 9a the return value is "00",
> while if it is any other hex value, it is properly returned.
> Can anyone please explain me if it some problem with Format() function and
> its workaround.
>


There is just one problem <g>:
You are trying to use a *numeric* format with a string value.
After all, sVar is declared as string and hex$ returns a string.
VB does its best to help you by internally converting the string
in sVar into a number - if there are only numerals - but if there
are characters like a, b, c, d, e, or f, how should it *know* the
text is really a hex number?
e.g. "dead" may be a word or a hex number.
To tell Format$ it is a hex number just set "&H" in front of the
string.
Debug.Print Format$("&H" & sVar, "00")
will work as you expect.

Using my example of "dead":
Debug.Print Format$("&H" & "dead", "00000")
returns correctly the decimal value of 57005 for the Hex
number DEAD, while
Debug.Print Format$("dead", "00000")
just returns dead

Helmut.

From: Larry Serflaten on

"Irfan S. Fazli" <IrfanSFazli(a)discussions.microsoft.com> wrote
> I have noticed that when:
> sVar = hex$(a byte value) ' value is within 0..255
> debug.print Format$(sVar, "00")
>
> if the value of sVar is like 1a, 2a, 3a, 4a, ... 9a the return value is "00",
> while if it is any other hex value, it is properly returned.
> Can anyone please explain me if it some problem with Format() function and
> its workaround.

The problem is with Format, it is assuming a pattern like #a and #p are
AM and PM notations. The workaround is simple enough:

sVar = Right$("00" & Hex$(a byte value), 2)
Debug.Print sVar

LFS


From: Jeff Johnson on
"Larry Serflaten" <serflaten(a)gmail.com> wrote in message
news:hvae6v$bg8$1(a)news.eternal-september.org...

> The problem is with Format, it is assuming a pattern like #a and #p are
> AM and PM notations. The workaround is simple enough:
>
> sVar = Right$("00" & Hex$(a byte value), 2)
> Debug.Print sVar

Only one zero* is needed at the front; you'll never get an empty string from
Hex$().



*Or, more specifically, <digits desired> - 1 zeroes.


 | 
Pages: 1
Prev: Saving form data
Next: Clear debug window