Page 1 of 1
Convert name to proper case
Posted: Wed Mar 02, 2011 11:43 pm
by Pauls74462
How to I convert a students name to proper case is they use all lower case?
Code: Select all
on mouseUp
put fld StudentsName into fld LabelSN
put "" into fld StudentsName
( convert students name to Students Name)
end mouseUp
Re: Convert name to proper case
Posted: Thu Mar 03, 2011 12:05 am
by jmburnod
Hi Pauls
You can use the upper function
Code: Select all
on mouseUp
put UpperFirstChar("john steinbeck")
end mouseUp
function UpperFirstChar pName
put the num of words of pName into nbW
repeat with i = 1 to nbw
put upper(char 1 of word i of pName) into char 1 of word i of pName
wait 1milliseconds
end repeat
return pName
end UpperFirstChar
Best
Jean-Marc
Re: Convert name to proper case
Posted: Thu Mar 03, 2011 12:19 am
by Pauls74462
jmburnod wrote:Hi Pauls
You can use the upper function
Code: Select all
on mouseUp
put UpperFirstChar("john steinbeck")
end mouseUp
function UpperFirstChar pName
put the num of words of pName into nbW
repeat with i = 1 to nbw
put upper(char 1 of word i of pName) into char 1 of word i of pName
wait 1milliseconds
end repeat
return pName
end UpperFirstChar
Best
Jean-Marc
confused, is this what my code should look like?
Code: Select all
on mouseUp
put fld StudentsName into fld LabelSN
put "" into fld StudentsName
put UpperFirstChar("john steinbeck")
end mouseUp
function UpperFirstChar pName
put the num of words of pName into nbW
repeat with i = 1 to nbw
put upper(char 1 of word i of pName) into char 1 of word i of pName
wait 1milliseconds
end repeat
return pName
end UpperFirstChar
Re: Convert name to proper case
Posted: Thu Mar 03, 2011 5:31 am
by dunbarx
A function takes a value and returns a result. A function can live anywhere; it is called as needed. They sort of work behind the scenes. Place it in the card or stack script and it will always be available.
It is then up to you to supply the data for the function to work with and and a destination to put it in. You could say:
answer upperFirstChar(yourText)
or:
put upperFirstChar(yourText) into field yourField
Try these in a button mouseUp handler. Supply the actual data in any way you like.
Write back if this is still not clear. Functions take just a little getting used to.
Craig Newman
Re: Convert name to proper case
Posted: Thu Mar 03, 2011 2:44 pm
by BvG
Uhm you really should not wait for 1 millisecond like that. If you fear that your repeat loop might block you should do something else. But with such a simple one that's almost impossible, even with tens of thousands of entries. To allow nonblocking repeat, use this line:
wait 0 seconds with messages
Re: Convert name to proper case
Posted: Thu Mar 03, 2011 4:04 pm
by dunbarx
I wasn't sure why there was a wait of any kind. Perhaps Jean-Marc just does this as a matter of course. The function will be instantaneous with all but huge amounts of data, and I don't think that is the case here.
But I agree that if one does, in general, unblock loops, the "wait with messages" form is the most robust.
Craig Newman
Re: Convert name to proper case
Posted: Thu Mar 03, 2011 4:05 pm
by BvG
The problem is, with "wait 1 millisecond" (no "with messages" at the end), one actually does not "rest" the processor, or give a break to the computer. all it does is slow the loop down noticeably

Re: Convert name to proper case
Posted: Thu Mar 03, 2011 6:59 pm
by Pauls74462
Pauls74462 wrote:jmburnod wrote:Hi Pauls
You can use the upper function
Code: Select all
on mouseUp
put UpperFirstChar("john steinbeck")
end mouseUp
function UpperFirstChar pName
put the num of words of pName into nbW
repeat with i = 1 to nbw
put upper(char 1 of word i of pName) into char 1 of word i of pName
wait 1milliseconds
end repeat
return pName
end UpperFirstChar
Best
Jean-Marc
confused, is this what my code should look like?
Code: Select all
on mouseUp
put fld StudentsName into fld LabelSN
put "" into fld StudentsName
put UpperFirstChar("john steinbeck")
end mouseUp
function UpperFirstChar pName
put the num of words of pName into nbW
repeat with i = 1 to nbw
put upper(char 1 of word i of pName) into char 1 of word i of pName
wait 1milliseconds
end repeat
return pName
end UpperFirstChar
This puts the name "john steinbeck" in proper case in a message box?
Re: Convert name to proper case
Posted: Thu Mar 03, 2011 7:15 pm
by Klaus
Hi Paul,
Pauls74462 wrote:This puts the name "john steinbeck" in proper case in a message box?
Yes, if you don't specify a target like "put tVariable
into field xyz" the output will go into the message box!
Best
Klaus
Re: Convert name to proper case
Posted: Sat Mar 05, 2011 8:32 pm
by Pauls74462
Klaus wrote:Hi Paul,
Pauls74462 wrote:This puts the name "john steinbeck" in proper case in a message box?
Yes, if you don't specify a target like "put tVariable
into field xyz" the output will go into the message box!
Best
Klaus
Code: Select all
on mouseUp
put fld StudentsName into fld LabelSN
put "" into fld StudentsName
put UpperFirstChar("john steinbeck") <<< I want the name of the student here.
end mouseUp
How do I get the students first & last name to be caps ans put it in the field LableSN
The fld StudentsName is the text box where the student types his/her name in.
The fld LableSN is the label where the students name proper case goes.
Re: Convert name to proper case
Posted: Sat Mar 05, 2011 9:16 pm
by jmburnod
Hi Paul,
If i understand what you want:
Code: Select all
on mouseUp
put fld "StudentsName" into tName
put "" into fld "StudentsName"
put UpperFirstChar(tName) into fld "LabelSN" --<<< I want the name of the student here.
end mouseUp
Best
Jean-Marc