|
-
Jan 14th, 2015, 12:35 PM
#1
Thread Starter
New Member
[RESOLVED] Strange Behaviour in Format function while using Hex function in VB4
Can someone explain why the Format function refuses to put leading zeros in front of the hexadecimal numbers A thru F in this code? 
Code:
For idx = 1 To 15 ' actually need to loop to 1024
TxtStr = Format(Hex(idx), "000")
Next
Is there a way to code this that will force the 'zeros' in front of the Hex number?
-
Jan 14th, 2015, 12:38 PM
#2
Re: Strange Behaviour in Format function while using Hex function in VB4
is txtstr dimmed as a string?
Why 3 0s hex values are even number of characters so 3 is strange. Unless of course you are trying to pad 3 0s in which case you need to add a 4th as 1 or more will be replaced by the value
-
Jan 14th, 2015, 01:04 PM
#3
Re: Strange Behaviour in Format function while using Hex function in VB4
You are saying: format a string to a string. Hex returns a string, not a number.
It would be similar result as: Format("X", "000")
One solution people generally use is to prefix the hex and take the right most n characters:
Code:
Right$("00" & Hex(idx), 3)
-
Jan 14th, 2015, 02:08 PM
#4
Thread Starter
New Member
Re: Strange Behaviour in Format function while using Hex function in VB4
Thank You, my friend, it does exactly what I need. The original programmer was using "Format". I feel stupid to not have thought about the "Right" function (play on words :-) ). My silly work around was to just use three loops ... 1 to 15 , 16 to 255 . 256 to 1024 and prefix the correct number of zeros. See what happens when you don't use some language for 10 years!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|