 |
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

September 3rd, 2005, 07:51 AM
|
Registered User
|
|
Join Date: Sep 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Changing length of string automatically
Hi Guys
I have to have a string a certain length, for example 10 characters.
So if a user submits a string such as "123456" I need to have a script that automatically inserts a character such as "$" to make up the difference in string length.
so my final output needs to be "123456$$$$"
each user will submit different length string so this needs to be done on the fly.
Any help would be appreciated.
Thanks
|

September 3rd, 2005, 10:05 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
dim uString
uString = "123456"
someName(uString,10)
function someName(str,paddTo)
dim uStringLen
uStirngLen = len(str)
do until uStingLen = paddTo
someName = str = str & "$"
uStingLen = uStingLen + 1
loop
end function
Wind is your friend
Matt
|

September 4th, 2005, 03:57 AM
|
Registered User
|
|
Join Date: Sep 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
HI matt
Thanks a stack. However with your code I'm getting a
"Cannot use parentheses when calling a Sub
testPage.asp, line 4, column 20
someName(uString,10)"
I tried this
"result = someName(uString,10)
response.write result"
but get a value of "False"
thanks
Ryan
|

September 4th, 2005, 04:05 AM
|
Registered User
|
|
Join Date: Sep 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok i thought perhaps it was because a few variables were spelt incorrectly like "uStingLen" instead of "uStringLen" but still get original error.
|

September 4th, 2005, 04:20 AM
|
Registered User
|
|
Join Date: Sep 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ok there was another error in the script *** someName = str = str & "$" ***
anyway, I played around till it worked, however I do not understand why it worked (Beginner). here is the code below. My question is after that.
<%option Explicit%>
<%
dim uString, result, uStringLen
uString = "123456"
function someName(str,paddTo)
dim uStringLen
uStringLen = len(str)
do until uStringLen = paddTo
str = str & "$"
uStringLen = uStringLen + 1
loop
end function
result=someName(uString,10)
response.write uString
%>
if I have the line "someName(uString,10)" I get the parentheses error.
however if put in the following "result=someName(uString,10)" and then response.write uString it works.
If I then response.write result I get no value however if I response.write uString to get the result.
What am i missing?
|

September 4th, 2005, 06:20 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
I didnt test it when i wrote the function, here is how it should be:
function someName(str,paddTo)
dim uStringLen
uStringLen = len(str)
someName = str
do until uStringLen = paddTo
someName = someName & "$"
uStringLen = uStringLen + 1
loop
end function
dim uString
uString = "123456"
response.write someName(uString,10)
I find it good practice to have the result held in the function name then you can use it on one line like so:
sql = INSERT INTO tble (fieldName)VALUES('" & someName(uString,10) & "');"
The extra parameter in the function makes it more useable. This way you can change the length of your string when you call the function without having to alter the function. Sorry bout the error in my first post.
Wind is your friend
Matt
|
|
 |