From: RDub on 12 Aug 2010 16:32 "Larry Serflaten" <serflaten(a)gmail.com> wrote in message news:i41kjl$5m3$1(a)news.eternal-september.org... > > "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 > Yup, that would work just fine too. I just never saw to potential for VB to think that the resultant number might (Ought to) be a time. Lesson learned! Rdub
From: Bob Butler on 12 Aug 2010 16:49 "RDub" <rweinerattrcrentdotcom> wrote in message news:Ozm46ulOLHA.5064(a)TK2MSFTNGP02.phx.gbl... > 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()! Not just format but any place VB attempts to coerce from string to numeric. Your initial version did numeric to string with the Hex function, then string to numeric as the first parameter to the format function, then numeric to string again as the result of the format. That's just begging for VB to apply a little ETC somewhere along the line. <g>
From: Jeff Johnson on 12 Aug 2010 17:07 "RDub" <rweinerattrcrentdotcom> wrote in message news:OVzFLclOLHA.1172(a)TK2MSFTNGP04.phx.gbl... > right("00" & hex(SomeByte),2) There's no need for two zeroes. Hex() will always return at least one character, so you only need Right$("0" & Hex$(SomeByte), 2)
From: Nobody on 12 Aug 2010 18:13 For any length up to 32 Bits: Public Function GetHex(ByVal i As Long, _ Optional ByVal HexWidth As Integer = 2) As String GetHex = Right$("00000000" & Hex$(i), HexWidth) End Function Usage: Debug.Pring GertHex(90)
First
|
Prev
|
Pages: 1 2 Prev: VarPtr() and StrPtr() questions Next: Print ACCESS 2003 report via VB6 Application |