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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zero Fill

Status
Not open for further replies.

Lambro

Programmer
Aug 22, 2001
258
US
I have a field on my form for dollars. I has a max length of 8 chars. I'm storing this field to my database. Say a user enters in the following, I need it zero filled and the decimal stripped off:

566.38 = 00056638
239.40 = 00023940
432 = 00043200 if the user didn't enter a decimal
 
Use this:
Code:
strEntered = "566.38"
WScript.Echo Pad(CStr(Int(strEntered)), 10, "0", True)
strEntered = "239.40"
WScript.Echo Pad(CStr(Int(strEntered)), 10, "0", True)
strEntered = "432"    
WScript.Echo Pad(CStr(Int(strEntered)), 10, "0", True)



Function Pad(strText, nLen, strChar, bFront)
 	Dim nStartLen
 	If strChar = "" Then 
 		strChar = "0"
 	End If
 	nStartLen = Len(strText)
 	If Len(strText) >= nLen Then
 		Pad = strText
 	Else
 		If bFront Then
 			Pad = String(nLen - Len(strText), strChar) & strText
 		Else
 			Pad = strText & String(nLen - Len(strText), strChar)
 		End If
 	End If
 End Function

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Here's my code:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript1.2" type="text/JavaScript1.2">
Function Pad(strText, nLen, strChar, bFront)
Dim nStartLen
If strChar = "" Then
strChar = "0"
End If
nStartLen = Len(strText)
If Len(strText) >= nLen Then
Pad = strText
Else
If bFront Then
Pad = String(nLen - Len(strText), strChar) & strText
Else
Pad = strText & String(nLen - Len(strText), strChar)
End If
End If
End Function
</script>

</head>

<body>
<form action="" method="get">
<input name="Text1" type="text" onBlur="Pad();" maxlength="10"><br>
<input name="Text2" type="text">
</form>
</body>
</html>

How do I use the Pad Function?
 
Basically, whenever you want to pad a string, call the pad function. If you post the line of code that inserts the info into your DB, I'll tweak it to pad.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Try:
objRS("DollarAmount")=Pad(CStr(Int(iDollarAmount)), 10, "0", True)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I entered in 44.99 into the textbox and it wrote 44.99 to my file.
 
If you simply Response.Write Pad(CStr(Int(iDollarAmount)), 10, "0", True

What do you get?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
i got: 0000000044 when I entered in 44.99 I wanted to get: 0000004499

 
Oops, my misunderstanding.

Response.Write Pad(Replace(CStr(iDollarAmount), ".", ""), 10, "0", True)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top