Posts: 1,556
Threads: 298
Joined: Dec 2002
Is there any specific way to display all numbers in a "000" format? I tried the USING command, but it doesn't seem to have that. What I'm trying to do is load files that are sorted as "File001.dat, File002.dat, File003.dat .......... File010.dat, File011.dat".
Posts: 525
Threads: 23
Joined: Oct 2004
well I thought that USING "000" would force the leading zeros to appear. Hmmm
if not you can always do something like:
Code:
IF NumericValue < 10 THEN
LeadingZeroes = "00"
ELSE IF NumericValue > 9 AND NumericValue <=99 THEN
LeadingZeroes = "0"
ELSE
LeadingZeroes = ""
END IF
FileName = "FILE" + LeadingZeroes + TRIM$(STR$(NumericValue))+".dat"
Should do the trick :-)
Posts: 1,556
Threads: 298
Joined: Dec 2002
Alright, I'll go with that. Thanks. =]
Posts: 525
Threads: 23
Joined: Oct 2004
Posts: 1,956
Threads: 65
Joined: Jun 2003
Rokkuman,
Here's a solution based on the same idea, but much simpler:
Code:
FileName$ = "FILE" + RIGHT$("000" + LTRIM$(STR$(NumericValue)) ,3)+".dat"
Note: You really only need 2 zeros up front, "00",
but using "000" makes what you're doing clearer.
*****
Posts: 525
Threads: 23
Joined: Oct 2004
I thought doing a STR$(Numeric) left a leading space for the possible minus (-) sign)
Posts: 500
Threads: 7
Joined: Jun 2005
Not in FB. In QB, it left a leading space for the minus sign, but in FB, that is changed. This makes things easier so you don't have to do this:
Code:
RIGHT$(STR$(variable), LEN(STR$(variable)) - 1)
This removes the first character and should only be used in QB if you know that a result will be positive. Otherwise, you would probably use a FUNCTION or a SUB to convert it to a string if you convert to strings numerous times:
Code:
FUNCTION varToStr$(variable)
IF SGN(variable) < 0 THEN
varToStr$ = STR$(variable)
ELSE
varToStr$ = RIGHT$(STR$(variable), LEN(STR$(variable)) - 1)
END IF
END FUNCTION
Edit: Untested, but it should work.
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Posts: 489
Threads: 34
Joined: Jan 2005
O_o in qb people used ltrim$( str$( somenum% ) ) :roll: :wink:
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Posts: 500
Threads: 7
Joined: Jun 2005
Quote:O_o in qb people used ltrim$( str$( somenum% ) ) :roll: :wink:
Except for people who didn't know that LTRIM$ existed. :wink:
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Posts: 1,845
Threads: 44
Joined: Aug 2002
Another way to do it is:
Code:
Const NumberOfZeros = 3
FileName$ = "file" + String$(NumberOfZeros - Len(LTrim$(Str$(NumericalValue))), "0") + LTrim$(Str$(NumericalValue))
Easily adjust number of preceding zeros