Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Take Input in proper without Changing Caps Lock on or off 1

Status
Not open for further replies.

KALP1

Programmer
Aug 26, 2016
102
0
0
IN
I want my app to take I/P in proper format i.e. as soon as user presses space or '.' or ',' next letter should be upper case otherwise small case.I don't want to change Caps On or Off.

How I would implement is in interactive change event of textbox, i would refresh I/P value restoring selstart value. Is there any other way to do that.
 
Handle KeyPress event of the textbox.

Borislav Borissov
VFP9 SP2, SQL Server
 
Some precaution must be made because you can select a portion of text and replace the entire selection with a dot.

Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
oFrm.Show()

DEFINE CLASS MyForm as Form
	ADD OBJECT txt1 as textBox WITH InputMask = REPLICATE("X",200),MaxLength = 200, width = 300
	
	PROCEDURE txt1.Keypress
		LPARAMETERS nKey,nShift
		LOCAL lnSelStart,lnSelLength
		IF m.nkey = 46 AND m.nshift = 0
			NODEFAULT
			lnSelStart = This.SelStart
			lnSelLength = This.SelLength
			This.InputMask = STUFF(This.InputMask,m.lnSelStart+3,m.lnSelLength,"")
			This.InputMask = STUFF(This.InputMask,m.lnSelStart+2,1,"!")
			This.InputMask = This.InputMask + REPLICATE("X",m.lnSelLength)
			This.SelStart = m.lnSelStart
			This.SelLength = m.lnSelLength
			DODEFAULT(m.nKey,m.nShift)
		ENDIF
	ENDPROC
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
Thanks Vilhelm,worked excellent. Never thought in this direction to change Inputmask dynamically. Will I have to do this for all punctuations after which I want capital letters
 
Vilhelm, there is 1 problem in it, if I use '.' at suppose position 3rd -> 'Ru.' , and then I delete text and again type say 'Rest' , then in this case I get O/p as 'ResT'
 
I would tackle this with interactivechange and change all letters after '.' and ','.

Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
oFrm.Show()

DEFINE CLASS MyForm as Form
   ADD OBJECT txt1 as textBox WITH MaxLength = 200, width = 300
   
   PROCEDURE txt1.InteractiveChange
      #Define ccPunctuations '.,'
      
      LOCAL lnCount1, lcChar, lnOccurrance, lnPosition
      LOCAL lnSelStart,lnSelLength
      
      lnSelstart = This.SelStart
      lnSelLength = This.SelLength
      
      FOR lnCount1 = 1 TO LEN(ccPunctuations)
         lcChar = SUBSTR(ccPunctuations, lnCount1,1)
         lnOccurrance = 1
         DO WHILE .T.
            lnPosition = AT(lcChar, This.Value, lnOccurrance)
            IF lnPosition = 0 OR lnPosition = LEN(This.Value)
               EXIT
            ENDIF
            This.Value = STUFF(This.Value, lnPosition+1, 1, UPPER(SUBSTR(This.Value,lnPosition+1,1)))
            lnOccurrance = lnOccurrance + 1
         ENDDO  
      ENDFOR     
      
      This.SelStart = m.lnSelstart
      This.SelLength = m.lnSelLength
   ENDPROC

Besides, though it's obvious, english only has upper case after a full stop, not after a comma. If you want to have uppercase also after a space after punctuation, you have to first get the position of the first non whitespace after a punctuation character.

Bye, Olaf.
 
Excellent Olaf, Exactly the way I had thought of.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top