
Leading/Trailing Zero algorithm....
Hi all...<BR><BR>Been trying today to craft a little handler that will take user input of numbers (like 2.3 or 13.76 or 234.7654) all with decimals and post it to a text file in the following format...<BR>00000000.0000000<BR>which is 8 zeros, the decimal, then 7 zeros...so it'd look like this when done for the above examples...<BR>00000002.3000000<BR>00000013.760000 0<BR>00000234.7654000<BR><BR>And I cant quite get it. Here's my code so far...<BR>'================================== ====================<BR><BR>nuexchangeName = rs.fields("EXCHANGERATE")<BR><BR>If Len(nuexchangeName & "") < 1 then<BR>'quick test to see if this is a null or empty cell...<BR> <BR>strAS400 = strAS400 & "00000000.0000000" <BR><BR>ELSE<BR>'<BR>'LEADING zeros...<BR>'<BR>' item here will be decimals like 3.2...or 17.65<BR><BR>decName1 = InStr(nuexchangeName, ".")<BR>' number of digits from left that is the decimal point<BR><BR>decName2 = (9  decName1)<BR>' get count of # of 0s to the left of the decimal<BR><BR>for n = 1 to decName2<BR><BR>exchangeFind = "0" & exchangeFind<BR>next<BR><BR>'<BR>'TRAILING zeros...<BR>'<BR><BR>decName3 = InStrRev(nuexchangeName, ".")<BR>' measure from the right side here...<BR><BR>decName4 = (8  decName3)<BR><BR>for n = 1 to decName4<BR><BR>nuexchangeName2 = "0" & nuexchangeName2<BR><BR>next<BR><BR><BR>' STRING Put together here....<BR>'<BR><BR>nuexchangeName3 = exchangeFind & nuexchangeName & nuexchangeName2<BR>' leading zeros followed by user input followed by trailing 0s<BR><BR>strAS400 = strAS400 & nuexchangeName3 '16 digits built to<BR>'====================================== =======================<BR><BR>Can anyone see my error. What I get is fine for the leading zeros, but for the trailing ones, it seems to be wonky. If the users' entered 12.45, then it runs fine. But if its 4.56 then it's two trailing zeros too long; if it's 234.55 then it's 1 trailing zero too short...<BR><BR>???<BR>Can someone point out my logic fault here?<BR><BR>Jim<BR>

RE: Leading/Trailing Zero algorithm....
Hello all...<BR><sigh> nevermind fellas....found it. I wasn't allowing for the length of the user string...so everything shifted accordingly.<BR><BR>Fixed same...but thanks!<BR><BR>;)<BR><BR>Jim

RE: Leading/Trailing Zero algorithm....
For the rear, you need to find out how many digits are after the decimal, right?<BR><BR>So, let's say you want 10 digits after the point (obviously alter this to your numbers needed)<BR><BR>Dim x<BR>x = "29.5"<BR><BR>numberOfZeros = 10  Len(Mid(x, InStrRev(x, ".") + 1))<BR><BR>x = x & String(numberOfZeros, "0")<BR><BR>Screw that looping stuff... makes it more convoluted.<BR><BR>If you need it for the leading zeros, you can use this formula as well.

****... 15 seconds too late
Hmmmm.... could've saved myself some typin'.

RE: Leading/Trailing Zero algorithm....
Well...thanks desertGhost...<BR>My own 14 lines are severely compacted into your own 4...<BR><BR>If that means that your 400% better 'n me, then I hope you get 400% better pay too!<BR><BR>;0<BR><BR>Jim

Heh, not likely
Ya could've even shortened it from there  might've been harder to read though.<BR><BR>I say, split the **** thing into an array...<BR><BR>Dim x, y, z<BR>x = "29.555"<BR>y = Split(x, ".")<BR><BR>z = (String(10  Len(y(0)), "0")) & y(0) & "." & y(1) & (String(10  Len(y(1)), "0"))<BR><BR>or something like that... untested, but should get you close.

RE: Heh, not likely
<grin> I'll leave that one till later in the summer to try and understand...<BR><BR>But I am trying your code as below...in another area that needs a format like this  0000.00000  10 digits altogether...<BR>'=========================== =========================<BR>' Leading zeros...<BR>Dim y, numberOfZeros<BR>y = nupriceName<BR><BR>numberOfZeros = 10  Len(Mid(y, InStr(y, ".") + 1)) <BR><BR>y = y & String(numberOfZeros, "0") <BR><BR> <BR>'Trailing zeros...<BR>Dim x, numberOfZeros1<BR>x = nupriceName<BR><BR>numberOfZeros1 = 10  Len(Mid(x, InStrRev(x, ".") + 1)) <BR><BR>x = x & String(numberOfZeros1, "0")<BR><BR>strAS400 = strAS400 & y & nupriceName & x '10 digits  built to<BR>'====================================== ==========<BR><BR>And it's all messed up..most likely because of my changes...<BR><BR>Can you look at this and figure out what I need done...<BR><BR>Jim<BR>

Gotta watch the +1
That's used for InStrRev so you don't get the decimal with it. You may want to play with that formula.<BR><BR>I'd say go the array route  you'll have to muck around if you want 10 digits TOTAL... what I have, gives you 10 digits on each side of the decimal. Your call.
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

