Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a 0 to the tail if a number is less then 10 on a parsed number

Status
Not open for further replies.

John1Chr

Technical User
Sep 24, 2005
218
US
Greetings!

Acutally, this is a continuation of thread705-1277401. Golom provided the code that has worked well for me except for one thing that I didn't tell him that I wanted it to do.

For example:
if a number is 1204500009 then give me 1245-09

If the tailend of this number is below 10 then add a zero to it so that it is a two digit tail. I keep goofing around with it but I can't get it to work. I don't want to mess up the existing code.

It works for these parses:

In the field,
if this number is 1204500090 then give me 1245-90
If the number is 1204500257 then give me 1245-257
If the number is 1204507890 then give me 1245-7890
If the number is 1204567890 then give me 1245-67890

Here is the code that Golom designed:


Public Function ParsedString(RawValue As String) As String
Dim NS As String
Dim EC As String
Dim C As String
Dim AddOn As Boolean
Dim n As Integer

NS = Left(RawValue,2) & Mid(RawValue,4,2) & "-"
EC = Mid(RawValue,6)
If Val(EC) <> 0 Then NS = NS & Val(EC)

If NOT IsNumeric(EC & "E0") Then
For n = 1 To Len(EC)
C = UCase(Mid(EC,n,1))
If C >= "A" AND C <= "Z" Then AddOn = True
If AddOn Then NS = NS & C
Next
End If

ParsedString = NS

End Function
 
Replace this:
If Val(EC) <> 0 Then NS = NS & Val(EC)
with this:
If Val(EC) <> 0 Then NS = NS & Format(Val(EC), "00")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top