Re: Allowing for Negative Numbers

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 03/31/04


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



Relevant Pages

  • Re: Emulating the Key operation ?
    ... The input cursor settles *before* the first character, ... When the user inputs a character into the already-filled field, ...     Certainly, my IE7 and recent Firefox versions exhibit that behaviour. ... <!DOCTYPE html> ...
    (comp.lang.javascript)
  • Re: Stupid Newbie Question Concerning CGI and Reading Forward Slashes
    ... read inputs from an HTML file. ... A couple of these inputs are textboxes that the user inputs a path in. ... there isn't do you suggest having the user use a different character ... It's not a common question, ...
    (comp.lang.python)
  • Re: Allowing for Negative Numbers
    ... That's what I was looking for Rick... ... >> user inputs to a textbox. ... > signs and the non-first character condition in one test). ...
    (microsoft.public.vb.general.discussion)
  • Re: How to avoid double entries inside a text box?
    ... I need also to append characters when the textbox is not ... Form_KeyDown event plus respond to Backspace, ... I have not double but triple repeat of the same character! ... Private Sub Form_KeyDown ...
    (microsoft.public.vb.general.discussion)
  • Re: How to avoid double entries inside a text box?
    ... It should allow all the normal operations textbox has when it is in focus ... I have not double but triple repeat of the same character! ... Then the same keystroke that your Form's key event has just ... the insertion point at the beginning!). ...
    (microsoft.public.vb.general.discussion)