Solved

first letter of each word

Posted on 2006-06-30
32
1,453 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now