From: RDub on
Guys/Gals

I need to display byte values in Hex format and preserve leading zeros. so I
came up with :
format(hex(SomeByte),"00")
to perform the deed. I just noticed an inconsistency with that code and
changed it to :
right("00" & hex(SomeByte),2)
which fixes my problem.

But I do not understand why the first form gives an incorrect result. I
just hate not knowing! Can someone please help out?

from the immediate window try this:
for i = 89 to 91 : ? i, format(hex(i),"00") : next
89 59
90 00 <--- What's up with this?
91 5B

and then this:
for i = 89 to 91 : ? i, right("00" & hex(i),2) : next
89 59
90 5A <--- Correct
91 5B

Rdub


From: Bob Butler on

"RDub" <rweinerattrcrentdotcom> wrote in message
news:OVzFLclOLHA.1172(a)TK2MSFTNGP04.phx.gbl...
> Guys/Gals
>
> I need to display byte values in Hex format and preserve leading zeros. so
> I came up with :
> format(hex(SomeByte),"00")
> to perform the deed. I just noticed an inconsistency with that code and
> changed it to :
> right("00" & hex(SomeByte),2)
> which fixes my problem.
>
> But I do not understand why the first form gives an incorrect result. I
> just hate not knowing! Can someone please help out?
>
> from the immediate window try this:
> for i = 89 to 91 : ? i, format(hex(i),"00") : next
> 89 59
> 90 00 <--- What's up with this?

Hex(90) = "5A" which VB is coercing to 5:00AM and then trying to apply the
"00" formatting to that.

?Format$("5A","hh")
05


From: Larry Serflaten on

"RDub" <rweinerattrcrentdotcom> wrote in message news:OVzFLclOLHA.1172(a)TK2MSFTNGP04.phx.gbl...
> Guys/Gals
>
> I need to display byte values in Hex format and preserve leading zeros. so I
> came up with :
> format(hex(SomeByte),"00")
> to perform the deed. I just noticed an inconsistency with that code and
> changed it to :
> right("00" & hex(SomeByte),2)
> which fixes my problem.
>
> But I do not understand why the first form gives an incorrect result. I
> just hate not knowing! Can someone please help out?
>
> from the immediate window try this:
> for i = 89 to 91 : ? i, format(hex(i),"00") : next
> 89 59
> 90 00 <--- What's up with this?
> 91 5B
>
> and then this:
> for i = 89 to 91 : ? i, right("00" & hex(i),2) : next
> 89 59
> 90 5A <--- Correct
> 91 5B
>
> Rdub
>
>


From: Larry Serflaten on

"RDub" <rweinerattrcrentdotcom> wrote

> I need to display byte values in Hex format and preserve leading zeros. so I
> came up with :
> format(hex(SomeByte),"00")
> to perform the deed. I just noticed an inconsistency with that code and
> changed it to :
> right("00" & hex(SomeByte),2)
> which fixes my problem.
>
> But I do not understand why the first form gives an incorrect result. I
> just hate not knowing! Can someone please help out?

Try this:

for i = 89 to 91 : ? i, format("&H" & hex(i),"00") : next


LFS


From: RDub on

"Bob Butler" <bob_butler(a)cox.invalid> wrote in message
news:i41k1n$vm2$1(a)news.eternal-september.org...
>
> "RDub" <rweinerattrcrentdotcom> wrote in message
> news:OVzFLclOLHA.1172(a)TK2MSFTNGP04.phx.gbl...
>> Guys/Gals
>>
>> I need to display byte values in Hex format and preserve leading zeros.
>> so I came up with :
>> format(hex(SomeByte),"00")
>> to perform the deed. I just noticed an inconsistency with that code and
>> changed it to :
>> right("00" & hex(SomeByte),2)
>> which fixes my problem.
>>
>> But I do not understand why the first form gives an incorrect result. I
>> just hate not knowing! Can someone please help out?
>>
>> from the immediate window try this:
>> for i = 89 to 91 : ? i, format(hex(i),"00") : next
>> 89 59
>> 90 00 <--- What's up with this?
>
> Hex(90) = "5A" which VB is coercing to 5:00AM and then trying to apply the
> "00" formatting to that.
>
> ?Format$("5A","hh")
> 05
>
Thanks Bob!

That was driving me crazy. I never would have guessed that VB would think
5A was a time value. Sheesh.. Note to self... Be wary of Format()!

Rdub