String Problem

DANY
08-10-2004, 05:21 PM
Hello to all,

Assume I have a field length of 10 digits long, a string type and the last four digits are considered to be the YEAR. Sometimes the user will enter it as shown below but i want it to be padded with leading zeros and also to pad the year

Before After (what I am looking for)
234/03 00024/2003
54576/99 54576/1999
567A/02 0567A/2002
78/98 00078/1998
786/2004 00786/2004
I need a funciton to pass the string value and as I type the value in the textbox, it will becomes as shown in the (AFTER) (what I am looking for.

thanks for any help.

b0b
08-10-2004, 06:33 PM
im sure there's a better way but this works

Dim TmpStr() As String

TmpStr = Split("786/2004", "/")

TmpStr(0) = Format$(TmpStr(0), "00000")

If Len(TmpStr(1)) < 4 Then 'if they've enter full year dont bother formatting
If TmpStr(1) >= 0 And TmpStr(1) < 90 Then 'checks year
TmpStr(0) = TmpStr(0) & "/" & Format$(TmpStr(1), "2000")
Else
TmpStr(0) = TmpStr(0) & "/" & Format$(TmpStr(1), "1900")
End If
Else
TmpStr(0) = TmpStr(0) & "/" & TmpStr(1)
End If

MsgBox TmpStr(0)

DANY
08-10-2004, 08:12 PM
Hi,
Seems to work but if you have something like this,
it does not padd the leading zeros.

TmpStr = Split("786A/2004", "/")

its becomes 0786/2004

should be 0786A/2004

good job. make life easier.

thanks a bunch


im sure there's a better way but this works

Dim TmpStr() As String

TmpStr = Split("786/2004", "/")

TmpStr(0) = Format$(TmpStr(0), "00000")

If Len(TmpStr(1)) < 4 Then 'if they've enter full year dont bother formatting
If TmpStr(1) >= 0 And TmpStr(1) < 90 Then 'checks year
TmpStr(0) = TmpStr(0) & "/" & Format$(TmpStr(1), "2000")
Else
TmpStr(0) = TmpStr(0) & "/" & Format$(TmpStr(1), "1900")
End If
Else
TmpStr(0) = TmpStr(0) & "/" & TmpStr(1)
End If

MsgBox TmpStr(0)

b0b
08-11-2004, 04:23 AM
Didn't notice the letters, well if you want to fix that then you can use the IsNumeric function, before you format the first half of the value check to see if it has letters in it. If IsNumeric returns false (its not a number) then use the String$ function to maually format the value by sticking the right number of zeros to the left of the value.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum