Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
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
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
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
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.
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
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
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.
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
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
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
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?
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.
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