Re: Allowing for Negative Numbers
From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 03/31/04
- Next message: sch: "Re: Locking code in VB 6.0"
- Previous message: Bob O`Bob: "Re: Allowing for Negative Numbers"
- In reply to: Brian Stigler: "Allowing for Negative Numbers"
- Next in thread: Brian Stigler: "Re: Allowing for Negative Numbers"
- Reply: Brian Stigler: "Re: Allowing for Negative Numbers"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 31 Mar 2004 15:32:26 -0500
> I've got a piece of code... (with help from this forum) that validates
> user inputs to a textbox.
>
> Currently, the textbox can hold any number with a specified number of
> decimal places. If the user attempts to enter a non-numeric character
other
> than "." the field flashes red and the keystroke is disallowed.
>
> Now... I would like to allow for negative numbers... but since "-" is a
> non-numeric character, it is rejected by the logic.
>
> I can add the "-" to the list of allowed chacacters by using Like
> "*[!0-9.-]*" and can eliminate multiple "-"s with the check of Like
> "*-*-*"...
>
> But here's the problem... How can I specify that the "-" can only be in
the
> first character position?????
>
> I am using the check ---> if Instr(1,text,"-")>1 to get it to work...
but
> I would think that there is a combination of wild card characters that
would
> work better...
>
> Can someone provide a suggestion?
Instead of checking for multiple "-" signs, just check that the minus sign
comes after the first character instead (that will catch the multiple "-"
signs and the non-first character condition in one test). Instead of this
.... Like "*-*-*" Then
do this
.... Like "?*-*" Then
and it will catch both conditions.
Rick - MVP
- Next message: sch: "Re: Locking code in VB 6.0"
- Previous message: Bob O`Bob: "Re: Allowing for Negative Numbers"
- In reply to: Brian Stigler: "Allowing for Negative Numbers"
- Next in thread: Brian Stigler: "Re: Allowing for Negative Numbers"
- Reply: Brian Stigler: "Re: Allowing for Negative Numbers"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|