Solved

first letter of each word

Posted on 2006-06-30
32
1,455 Views
Last Modified: 2008-01-16

hello

I want the every word in a sentence to be capitised, I founf this snippet for it but it gives me the error. below is my snippet for the function and below that is the error. I am grateful for help

kenny

<%
' first letter of each word only
        Function Proper(txt)
                tmp = Split(txt, " ")
                For Each Item In tmp
                        Proper = Proper & UCase(Left(Item, 1)) & 
LCase(Right(Item,
Len(Item) - 1)) & " "
                Next
                Proper = Left(Proper, Len(Proper) - 1)
        End Function

%>

------------------------------------------------ error below

Microsoft VBScript compilation error '800a03ea'

Syntax error

/star_detail.asp, line 243

Proper = Proper & UCase(Left(Item, 1)) &
----------------------------------------^




0
Comment
Question by:thatelvis
  • 15
  • 11
  • 2
  • +2
32 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17017893
try changing this:

tmp = Split(txt, " ")

for this:

tmp = Split(trim(txt), " ")
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17017996
thank you I tried that I get the following error

Microsoft VBScript compilation error '800a03ea'

Syntax error

/star_detail.asp, line 199

Proper = Proper & UCase(Left(Item, 1)) &
----------------------------------------^
0
 
LVL 23

Expert Comment

by:apresto
ID: 17018010
what value are you feeding into the function?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:thatelvis
ID: 17018067
I want the function to work with this

<%= proper(CropSentence((RecElvismostofuser.Fields.Item("country_usr").Value), 15, "...")) %>

it is a list of countries and some are more then one word, so I do need each word to be capital


regards

kenny
0
 
LVL 23

Expert Comment

by:apresto
ID: 17018112
can you try sticking it in a variable first and printing it to the screen so we can see where it is erroring:

<%
Dim properCountry
properCountry = RecElvismostofuser.Fields.Item("country_usr").Value
Response.write(properCountry & "<br>")
Response.flush()
proper( CropSentence(properCountry, 15, "...") )

%>

When it stops printing we know where it is erroring and can tell if its the string value or function
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17018227
UNITED KINGDOM

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CropSentence'

/star_detail.asp, line 216
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17018637
are you stil there.

regards

kenny
0
 
LVL 23

Expert Comment

by:apresto
ID: 17018698
Sorry i must have missed your mail, i'll have a gander now
0
 
LVL 23

Expert Comment

by:apresto
ID: 17018735
try this:

<%
Dim properCountry
properCountry = RecElvismostofuser.Fields.Item("country_usr").Value
Response.write(properCountry & "<br>")
Response.flush()
dim sentence
sentence = proper( CropSentence(properCountry, 15, "...") )

%>
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17018826
ok when i try that i get

UNITED KINGDOM

I am not trying to crop here as I have a function to do that already, what I want is to only have the first letter of each word capitalised.

regards

kenny

0
 
LVL 23

Expert Comment

by:apresto
ID: 17018886
i know your not, but you need to assign the result of the functions to something.

i.e

dim sentence
sentence = proper( CropSentence(properCountry, 15, "...") )
response.write Sentence

then you can see before and after results
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17019000
ok


thanks for that, all my letersare capital still

on applying this

<%
Dim properCountry
properCountry = RecElvismostofuser.Fields.Item("country_usr").Value
Response.write(properCountry & "<br>")
Response.flush()
dim sentence
sentence = proper( CropSentence(properCountry, 15, "...") )

%>

I get this   UNITED KINGDOM


regards

kenny
0
 
LVL 23

Expert Comment

by:apresto
ID: 17019015
Yes but add this at the bottom:

Response.write(Sentence)
0
 
LVL 23

Expert Comment

by:apresto
ID: 17019019
You should get

UNITED KINGDOM
United Kingdom
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17019050
nope only one

UNITED KINGDOM


i
0
 
LVL 23

Expert Comment

by:apresto
ID: 17019081
ok, your Proper or CropSentence Function dont seem to be returning any values, i woudl suggest testing them with dummy values, to see which one is failing.

I am testing everything at my end and am not having any problems which is why i am finding it hard to debug
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17019094
<%
Dim properCountry
properCountry = Recmostofuser.Fields.Item("country_usr").Value
Response.write(properCountry & "<br>")
Response.flush()
dim sentence
sentence = proper( CropSentence(properCountry, 10, "...") )
Response.write(Sentence)


%>      

that gives me

UNITED KINGDOM
United kin...

how can i seperat the functions though. i have the char count on my page already and it is used where needed.

regards

0
 
LVL 23

Expert Comment

by:apresto
ID: 17019120
Use this instead - replace the lot

<%
Dim properCountry
Country = Recmostofuser.Fields.Item("country_usr").Value

Dim sentence, capital, capitalSentence
sentence = CropSentence(Country, 10, "...")
capital = proper( Country )
capitalSentence = proper( sentence)

Response.write(sentence & "<br>")
Response.write(proper & "<br>")
Response.Write(capitalSentence  & "<br>")
%>

that way you can call which ever one you want
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17019187
wowa

I get this

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CropSentence'

/star_detail.asp, line 252


when I have use this

<%
Dim properCountry
Country = Recmostofuser.Fields.Item("country_usr").Value

Dim sentence, capital, capitalSentence
sentence = CropSentence(Country, 10, "...")                <<<<<<<<<<<<<<<<<< this is line 252
capital = proper( Country )
capitalSentence = proper( sentence)

Response.write(sentence & "<br>")
Response.write(proper & "<br>")
Response.Write(capitalSentence  & "<br>")
%>
0
 
LVL 23

Expert Comment

by:apresto
ID: 17019209
wrap a trim() arond country

I'm off home now but will check back in when i get home
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17019243
gosh I am totally lost here, I would have prefered a single funtion for this and apply both the crop and the capital seperate.

regards

kenny
0
 
LVL 16

Expert Comment

by:sam85281
ID: 17020322
Any reason you can't just use CSS in your app?

Example:

<span style='text-transform: uppercase;'>YOUR TEXT OR CODE TO GENERATE TEXT HERE</span>

That will capitalize the first letter of each word.

-Sam
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17020539
Thanks Sam,
I would hav preferedcss, but i dont want upper case, I want every word in a sentence to be capital. not the entire word or sentence.

regards

k
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17020904
I think he wants:

text-transform: capitalize;

0
 
LVL 1

Author Comment

by:thatelvis
ID: 17021012
wowa eddie,
does what is that like for compatability,

regards

k
0
 
LVL 16

Expert Comment

by:sam85281
ID: 17021557
Yes,

uppercase for just the first letter, capitalize for all the letters

-Sam
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17023484
Hi sam, that wont work if the letters are already capital.

<table width="220" border="0" cellpadding="2" style="style="text-transform: capitalize;">
  <tr>
    <td>UNITED KINGDOM</td>
  </tr>
</table>

regards

k
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17023620
this question is closed , i have re asked it as I am in need of an instant reply, thanks al for your help.

regards

kenny
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17026933
Sam, you are incorrect, capitalize if for the First Letter Only and uppercase
is for ALL CAPS.
0
 
LVL 1

Author Comment

by:thatelvis
ID: 17027016
below did the trick


this will capitilise every word in a sentence.

<%
function proper(str)
  proper = ""
  aStr = split(str," ")
  for i = 0 to ubound(aStr)
    proper = proper & ucase(left(aStr(i),1)) & lcase(right(aStr(i),len(aStr(i))-1)) & " "
  next
  proper = rtrim(proper)
end function
 %>


<%= proper(CropSentence((Recmostofuser.Fields.Item("country_usr").Value),10,"...")) %>



----------------------------------------------------------------------------------------------------


'this is for the first letter only and nothing else.


function Proper(str)
  Proper = ucase(left(str,1)) & lcase(right(str,len(str)-1))
end function



<%=Proper(Reclistall.Fields.Item("firstname_usr").Value)%>
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 17061359
Closed, 400 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Blog posts not showing up on Blog page 7 58
remove border from element 5 78
jquery to restrict certain words from input in form 11 34
Divi Theme - extra fonts I don't want 13 25
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question