HighDots Forums  

variables and functions

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss variables and functions in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
twocans
 
Posts: n/a

Default variables and functions - 07-01-2006 , 12:14 PM






Hello

I have two functions below, i also have two variables country_usr and
region_usr , besides having applied the function Cropsentence to
country_user I also need to apply the function Proper to it, my question is
how can I appy both functions to one variable. any help gratefully received
k

<%
' this will crop a sentence
Function CropSentence(strText, intLength, strTrial)
If Len(strText) > intLength Then
CropSentence = Left(strText, intLength) & strTrial
Else
CropSentence = strText
End If
End Function
%>

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


<%= CropSentence((Recmostofuser.Fields.Item("country_u sr").Value), 10,
"...") %>

<%= CropSentence((Recmostofuser.Fields.Item("region_us r").Value), 10, "...")
%>







Reply With Quote
  #2  
Old   
Gary White
 
Posts: n/a

Default Re: variables and functions - 07-01-2006 , 12:43 PM






On Sat, 1 Jul 2006 17:14:26 +0100, "twocans" <buyme (AT) guinness (DOT) com> wrote:

Quote:
%= CropSentence((Recmostofuser.Fields.Item("country_u sr").Value), 10,
"...") %
<%=
Proper(CropSentence((Recmostofuser.Fields.Item("co untry_usr").Value),
10,
"...")) %>

Gary


Reply With Quote
  #3  
Old   
twocans
 
Posts: n/a

Default Re: variables and functions - 07-01-2006 , 12:51 PM



Thanks Gary,
<%= Proper(CropSentence((Recmostofuser.Fields.Item("co untry_usr").Value),10,
"...")) %>

i had tried that earlier but as soon as I apply both then the proper
function wont work. i am struggling

kenny










"Gary White" <reply (AT) newsgroup (DOT) please> wrote

Quote:
On Sat, 1 Jul 2006 17:14:26 +0100, "twocans" <buyme (AT) guinness (DOT) com> wrote:

%= CropSentence((Recmostofuser.Fields.Item("country_u sr").Value), 10,
"...") %

%=
Proper(CropSentence((Recmostofuser.Fields.Item("co untry_usr").Value),
10,
"...")) %

Gary



Reply With Quote
  #4  
Old   
twocans
 
Posts: n/a

Default Re: variables and functions - 07-01-2006 , 01:01 PM



I take it back it does work, but the proper function needs to be changed, I
wanted to have a capital on each word of a sentence not just the first
letter. if you have a snippet for that i would be grateful. below is what I
have but it will only change the first letter of a sentence.


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






"twocans" <buyme (AT) guinness (DOT) com> wrote

Quote:
Thanks Gary,
%=
Proper(CropSentence((Recmostofuser.Fields.Item("co untry_usr").Value),10,
"...")) %

i had tried that earlier but as soon as I apply both then the proper
function wont work. i am struggling

kenny










"Gary White" <reply (AT) newsgroup (DOT) please> wrote in message
news:ng9da2tlvlr2dji5r91eno7q2q4cv8g3p3 (AT) 4ax (DOT) com...
On Sat, 1 Jul 2006 17:14:26 +0100, "twocans" <buyme (AT) guinness (DOT) com> wrote:

%= CropSentence((Recmostofuser.Fields.Item("country_u sr").Value), 10,
"...") %

%=
Proper(CropSentence((Recmostofuser.Fields.Item("co untry_usr").Value),
10,
"...")) %

Gary





Reply With Quote
  #5  
Old   
Gary White
 
Posts: n/a

Default Re: variables and functions - 07-01-2006 , 01:49 PM



On Sat, 1 Jul 2006 18:01:18 +0100, "twocans" <buyme (AT) guinness (DOT) com> wrote:

Quote:
I take it back it does work, but the proper function needs to be changed, I
wanted to have a capital on each word of a sentence not just the first
letter. if you have a snippet for that i would be grateful. below is what I
have but it will only change the first letter of a sentence.

Hmmm ... as you may know, I'm more of a PHP guy. PHP has a ucwords()
function to do just that. I'm not seeing anything similar in my VBScript
reference. Unless someone more versed in VBScript comes along, I'd guess
you'd have to split the string into the individual words, apply the
Proper function to each one, then join them back together.

Gary


Reply With Quote
  #6  
Old   
twocans
 
Posts: n/a

Default Re: variables and functions - 07-01-2006 , 02:04 PM



Thanks Gary, I got it working.


the snippets are below for any one else who need one is for cropping a
sentence and the other is for first letter capital of each 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
%>

<%
' this will crop a sentence
Function CropSentence(strText, intLength, strTrial)
If Len(strText) > intLength Then
CropSentence = Left(strText, intLength) & strTrial
Else
CropSentence = strText
End If
End Function
%>




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



Reply With Quote
  #7  
Old   
Gary White
 
Posts: n/a

Default Re: variables and functions - 07-01-2006 , 07:00 PM



On Sat, 1 Jul 2006 19:04:53 +0100, "twocans" <buyme (AT) guinness (DOT) com> wrote:

Quote:
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

This (untested) may be slightly more efficient:

function proper(str)
aStr=split(str," ")
for i=0 to ubound(aStr)
aStr(i)=ucase(left(aStr(i),1)) & mid(aStr(i),2)
next
proper = join(aStr," ")
end function

Gary


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.