Classic ASP (VBScript) request

B

Badass Scotsman

Hello,

Couldn't find a classic ASP Usenet group, hopefully someone here will know
the answer.

I have a string called "FirstName" which will may be anything up to 20
characters in length ( I gather this string using
Request.Form("FirstName") ). However if it is less than 20 characters, I
would like the string to "expand" to 20 by using SPACES. IE, the String
FirstName should ALWAYS be 20 characters long, regardless of the user input.

Gary would become: "Gary " (Gary plus 16 spaces)
Bryan would become: "Bryan " (Bryan plus 15 spaces)
Pauline would become: "Pauline " (Pauline plus 13 spaces)

I would like this string to convert itself to 20 characters long when the
page loads if possible. I will also be doing this for other field names
such as Surname, HomeTelephone and WorkTelephone.

Any help greatly appreciated.

Regards,

Gary.
 
B

Badass Scotsman

OK I tried this, seems to work, sure there is an easier way though! :)

<%
FirstName = Request.QueryString("FirstName")
FirstNameLength = len(FirstName)
FirstNameRequiredLength = 100
FirstNameRequiredSpaces = FirstNameRequiredLength - FirstNameLength

For i = FirstNameLength To FirstNameRequiredLength -1
ActualSpace = " " & ""&ActualSpace&""
Next

FullNameWithSpaces = ""&FirstName&"" & ""&ActualSpace&""
%>
 
J

Josh Twist

Not that I'm offended, but what was wrong with my suggestion? Maybe an
explanation will help:

OK, first we add 20 spaces to the first name (the space function just
generates a string with the specified number of spaces):
Request.Form("FirstName") & space(20)

Next we chop the combination to only give us the first twenty
characters:
Left(combination, 20)

Combine the two:
Left(Request.Form("FirstName") & space(20), 20)

Feels a little neater maybe?
 
B

Badass Scotsman

Josh Twist said:
Not that I'm offended, but what was wrong with my suggestion? Maybe an
explanation will help:

OK, first we add 20 spaces to the first name (the space function just
generates a string with the specified number of spaces):
Request.Form("FirstName") & space(20)

Next we chop the combination to only give us the first twenty
characters:
Left(combination, 20)

Combine the two:
Left(Request.Form("FirstName") & space(20), 20)

Feels a little neater maybe?


Sorry, I had already done what I posted when I read yours, and also I am not
really sure how to implement it - I am not really that good at ASP. Could
you show me the full code for a working sample so I can try? Just for the
one string,

Regards,

Gary.
 
B

Badass Scotsman

Josh Twist said:
Not that I'm offended, but what was wrong with my suggestion? Maybe an
explanation will help:

OK, first we add 20 spaces to the first name (the space function just
generates a string with the specified number of spaces):
Request.Form("FirstName") & space(20)

Next we chop the combination to only give us the first twenty
characters:
Left(combination, 20)

Combine the two:
Left(Request.Form("FirstName") & space(20), 20)

Feels a little neater maybe?


Oh, also thank you - much neater too :)

Regards,

Gary.
 
J

Josh Twist

Here you go:

<%
FullNameWithSpaces = Left(Request.Form("FirstName") & space(20), 20)
%>
 
B

Badass Scotsman

Thank you John, I will post my entire page to you when I finish - its great
that guys like you are on hand to help.

Gary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top