Page 1 of 1

How to capitalize the first letter

Posted: Mon Sep 21, 2015 8:18 am
by golive
When typing into a field, how can I automatically capitalize the first letter :?:

Example:
The user types: car seat cover.
I want it to show as: Car seat cover.

Re: How to capitalize the first letter

Posted: Mon Sep 21, 2015 8:39 am
by jmburnod
Hi golive,

Just use toUpper toLower functions

Code: Select all

put "car seat cover." into tMystring
put toUpper(char 1 of tMystring) into char 1 of tMystring
put tMystring
Best regards
Jean-Marc

Re: How to capitalize the first letter

Posted: Mon Sep 21, 2015 8:42 am
by golive
jmburnod wrote:Hi golive,

Just use toUpper toLower functions

Code: Select all

put "car seat cover." into tMystring
put toUpper(char 1 of tMystring) into char 1 of tMystring
put tMystring
Best regards
Jean-Marc

Thanks for your reply. I would like to do it live; while the user is typing in the first c, it changes it to C and carries on accepting the rest of the input.

This is what I tried (but it doesn't work):

Code: Select all

local sFirst
put false into sFirst

on keyDown tCharacter
   if not sFirst then
      put toUpper(tCharacter) into tCharacter
      put true into sFirst
   else 
      pass keyDown
   end if
end keyDown

Re: How to capitalize the first letter

Posted: Mon Sep 21, 2015 9:06 am
by richmond62
I'm not sure how helpful this is, but I have just knocked together a wee stack called "Kapital" [attached here]
that contains a textField "feeld" and a cardScript:

on keyDown KEE
put toUpper (KEE) after fld "feeld"
end keyDown

I hope it is of some use.

Re: How to capitalize the first letter

Posted: Mon Sep 21, 2015 9:15 am
by jmburnod
Hi golive

What doesn't work ?
Is this better for you ?

Code: Select all

on keyDown tCharacter
   get the num of chars of fld "MyField"
   if it  = 0 then
            put toUpper(tCharacter) into fld "MyField"
      select after field "myField"
   else 
      pass keyDown
   end if
end keyDown
Jean-Marc

Re: How to capitalize the first letter

Posted: Mon Sep 21, 2015 9:31 am
by richmond62
That solution certainly seems OK IFF you want to capitalise the first letter of the whole text.

It might be a bit more complicated if you want to capitalise the first letter of ALL the words in the field.

Re: How to capitalize the first letter

Posted: Mon Sep 21, 2015 1:58 pm
by dunbarx
I think the OP wants to capitalize only the first letter of the entire body of text. But then what happens if the user types a period? Does that trigger another round?

In any case, golive, Jean-Marc's post gives you a hint. You already know about how to make the "keyDown" message work for you.

Craig Newman

Re: How to capitalize the first letter

Posted: Tue Sep 22, 2015 2:51 am
by golive
jmburnod wrote:Hi golive

What doesn't work ?
Is this better for you ?

Code: Select all

on keyDown tCharacter
   get the num of chars of fld "MyField"
   if it  = 0 then
            put toUpper(tCharacter) into fld "MyField"
      select after field "myField"
   else 
      pass keyDown
   end if
end keyDown
Jean-Marc
Yes thanks.

However, there is still an issue.
Type in something. Delete it, then type again. All good so far.

Now type in something. Select it by double-clicking. Now type in something new. It doesn't work anymore; does not capitalize the first letter.

Why?

Here is a stack to test it:
CapOne.zip
(789 Bytes) Downloaded 219 times

Re: How to capitalize the first letter

Posted: Tue Sep 22, 2015 6:25 am
by bn
Hi golive,

try

Code: Select all

on keyDown tCharacter
   if word 2 of the selectedChunk = 1 then
      put toUpper(tCharacter) into fld "fldCapFirst"
      select after field "fldCapFirst"
   else
      pass keyDown
   end if
end keyDown
selectedChunk -> dictionary
I would play around with it a bit to get familiar with selectedChunk.

Kind regards
Bernd

Re: How to capitalize the first letter

Posted: Wed Sep 23, 2015 1:06 am
by golive
bn wrote: selectedChunk -> dictionary
I would play around with it a bit to get familiar with selectedChunk.
Hi Bernd
Very good!

I would not have found selectedChunk without you, thanks :!: