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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

0000 as user types characters replace 0 from the right

Status
Not open for further replies.

lashwarj

IS-IT--Management
Nov 1, 2000
1,067
US
How would i make a text box have a value of 0000 and as the user types it replaces the 0 from the right, making the value always a 4 digit PADR() like function, but the user sees this as they type
 
Here's a rough start.
Add 2 class variables to the form (properties).
Call them, say, 'pos' and 'val'
where pos with point to the current '0' in '0000' and
val will be the current value of the text box.
In the Textbox When Method, put the following code:
Store "0000" to This.Value,Thisform.val
Thisform.pos = 4
In the Textbox GotFocus Event put ...
Set cursor off
In the Textbox LostFocus Event put ...
Set cursor on
In the Textbox InteractiveChange Event put ...
This.Value = Thisform.val
In the Textbox KeyPress Event put ...
do case
case 48<=nKeyCode and nKeyCode<=57 and Thisform.pos > 0
Thisform.val = ;
stuff(Thisform.val,Thisform.pos,1,chr(nKeyCode))
Thisform.pos = Thisform.pos - 1
case nKeyCode = 4 and Thisform.pos < 4
Thisform.pos = Thisform.pos + 1
Thisform.val = ;
stuff(Thisform.val,Thisform.pos,1,&quot;0&quot;)
This.value = Thisform.val
endcase
 
i am all set thank you, all I ended up needing to do was change my method around i was doing stuff in the wrong order.

I ended up using the PADR() Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top