Custom textbox entries....Keypress question 
Author Message
 Custom textbox entries....Keypress question

I need a textbox that will only accept values in the range of -4.00 to 3.00
(i.e. -2.33, 1.24, -3.99, etc)

The problem is:

1. I want to allow the "-" character, but only as the first digit (do not
allow ".3-2" for example).
2. I would like the text box to automatically display the ".", if the first
digit is 1 to 4, or the first two digits are -1 to -4.
3. I want to disallow any number > 4 in position 2 (if pos 1 is "-", or
disallow anything > 3 in position 1 if nothing has been entered.

Is this going overboard on input validation? I'll be validating the actual
value on lostfocus; I realize I could just limit a value like "9.232" to
"3.00".

I've looked at the masked edit box, but it doesn't give me anything in the
way of allowing the "-" character, and I'm not crazy about it anyway.

Anybody have any fancy smancy keypress, text changed type code to do this?
Otherwise I'll probably just use another control for the "+" or "-" (would
rather not though).

Thanks,

Calan



Tue, 03 May 2005 14:17:05 GMT  
 Custom textbox entries....Keypress question
Calan,

Have a look in the messages posted today in the comp.lang.visual.basic for a
the thread with subject "AutoFormat TextBox Entry: ab1234 --> AB 1234". In
particular, look at the 2 messages from me (Rob Strover).  They may provide
a start for you to do what you require.

After you've looked there, if you've any questions about the postings please
feel free to ask me.

BTW, I noticed after I posted the second message that I'd left out a few
vital lines of code, not that, in any case, the code covers all
possiblities. [it's not been checked *that* well :-)]

(1)  A variable declaration at start of Text1_Change sub:

    Static bSpaceInserted As Boolean

and

(2)  immediately after the  sCurrLastChar = Right$(sText, 1) line:

    If sPrevLastChar = Space$(1) Then
        bSpaceInserted = False
    End If


Quote:
> I need a textbox that will only accept values in the range of -4.00 to
3.00
> (i.e. -2.33, 1.24, -3.99, etc)

> The problem is:

> 1. I want to allow the "-" character, but only as the first digit (do not
> allow ".3-2" for example).
> 2. I would like the text box to automatically display the ".", if the
first
> digit is 1 to 4, or the first two digits are -1 to -4.
> 3. I want to disallow any number > 4 in position 2 (if pos 1 is "-", or
> disallow anything > 3 in position 1 if nothing has been entered.

> Is this going overboard on input validation? I'll be validating the actual
> value on lostfocus; I realize I could just limit a value like "9.232" to
> "3.00".

> I've looked at the masked edit box, but it doesn't give me anything in the
> way of allowing the "-" character, and I'm not crazy about it anyway.

> Anybody have any fancy smancy keypress, text changed type code to do this?
> Otherwise I'll probably just use another control for the "+" or "-" (would
> rather not though).

> Thanks,

> Calan



Tue, 03 May 2005 14:37:55 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Textbox Data Entry Problems using keypress (Newbie)

2. Trap Keypress to igmore non numeric entries

3. Controlling Data Entry via KeyPress (help required here)

4. Textbox Filtering using KeyPress

5. Handling Keypress on a textbox

6. KeyPress Even? (TextBox and ComboBox)

7. KeyPress event in TextBoxes

8. Changing the textbox input at keypress

9. KeyPress Event - TextBox

10. Keypress event for textbox

11. Keypress and textbox validation woes

12. textbox keypress - change the key thats pressed ?

 

 
Powered by phpBB® Forum Software