Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: marulam acong
  Where is marulam acong?
 bogor
 Indonesia
 marulam acong
 To: Tamar Granor
  Where is Tamar Granor?
 Elkins Park
 Pennsylvania - United States
 Tamar Granor
 Tags
Subject: RE: Keyboard manipulation
Thread ID: 345228 Message ID: 345311 # Views: 51 # Ratings: 0
Version: Visual FoxPro 6 Category: Forms
Date: Tuesday, May 22, 2012 12:16:01 PM         
   


> > Dear All,
> >
> > Currently i'm developing POS for client and i have problem when they ask me to manipulate the '0' in the keyboard. What they want is when the '0' key is pressed then it will shows '00' instead of '0'
>
> Presumably, they only want this in certain situations (like after a decimal point). Create a subclass of textbox for those cases. In the subclass, use the KeyPress method to figure out when you're in the situation that class for adding the extra 0. Assuming it is for typing to the right of the decimal point, you might try something like this (which is untested):
>
>
> LOCAL nPointPos, lHandled
> 
> lHandled = .F.
> nPointPos = AT(".", This.Value)
> IF m.nPointPos > 0 and This.SelStart > m.nPointPos
>   * Cursor is to the right of the decimal point
>   IF m.nKeyCode = ASC("0")
>      This.Value = LEFT(This.Value, This.SelStart) + "00" + SUBSTR(This.Value, This.SelStart + 1)
>      lHandled = .T.
>      NODEFAULT
>   ENDIF
> ENDIF
> 
> IF NOT m.lHandled
>    DODEFAULT(m.nKeyCode, m.nShiftAltCtrl)
> ENDIF
> 

>
> Of course, if this is for typing to the right of the decimal point, you could just tell them not to worry about it, since leaving that blank will insert the necessary zeroes.
>
> Tamar


Dear Tamar,

I tried the code from the example of you code, its work with some problem.
Here is the code

Object : Text1 Procedure : Keypress

LPARAMETERS nKeyCode, nShiftAltCtrl
if nkeycode=48
this.value=left(this.value,this.selstart)+"00"+subs(this.value,this.selstart+1)
endif

i have 2 problems :

1. the cursor cannot go to the end of the value, so i have to press END key to make it to the end of the value
so i can continue to type the value i want to put.

2. everytime i press '0' value, in the beggining of the value will be added '0'
for example : if i press '10' it will be added to be '010' and so on

Please kindly help me. thanks

ENTIRE THREAD

Keyboard manipulation Posted by marulam acong @ 5/21/2012 5:16:27 AM
RE: Keyboard manipulation Posted by onytoo @ 5/21/2012 12:52:16 PM
RE: Keyboard manipulation Posted by marulam acong @ 5/22/2012 11:51:05 AM
RE: Keyboard manipulation Posted by Jun Tangunan @ 5/24/2012 5:18:08 AM
RE: Keyboard manipulation Posted by David Mustakim @ 5/23/2012 8:17:08 PM
RE: Keyboard manipulation Posted by Cetin Basoz @ 5/21/2012 1:02:27 PM
RE: Keyboard manipulation Posted by Tamar Granor @ 5/21/2012 10:22:16 PM
RE: Keyboard manipulation Posted by marulam acong @ 5/22/2012 11:46:25 AM
RE: Keyboard manipulation Posted by Samir H. @ 5/22/2012 4:46:48 PM
RE: Keyboard manipulation Posted by marulam acong @ 5/22/2012 5:55:23 PM
RE: Keyboard manipulation Posted by onytoo @ 5/22/2012 6:32:53 PM
RE: Keyboard manipulation Posted by Muhammad Majid Ali Attari @ 5/24/2012 7:38:59 AM
RE: Keyboard manipulation Posted by David Mustakim @ 5/23/2012 8:22:44 PM
RE: Keyboard manipulation Posted by onytoo @ 5/24/2012 2:58:21 AM
RE: Keyboard manipulation Posted by marulam acong @ 5/22/2012 12:16:01 PM
RE: Keyboard manipulation Posted by David Mustakim @ 5/24/2012 7:20:34 AM
RE: Keyboard manipulation Posted by David Mustakim @ 5/30/2012 11:31:20 AM
RE: Keyboard manipulation Posted by onytoo @ 5/30/2012 3:57:13 PM