Zip Code Number Only? 
Author Message
 Zip Code Number Only?

I can't remember how to make sure a user can't input a letter into a number
field like zip code.  Please help me.  I'm a VB wannabe.
Thanks


Tue, 30 Oct 2001 03:00:00 GMT  
 Zip Code Number Only?


Quote:
> I can't remember how to make sure a user can't input a letter into a
number
> field like zip code.  Please help me.  I'm a VB wannabe.
> Thanks

Using the IsNumeric function is probably the easiest way, though it's
not necessarily the most elegant.  You could, for instance, put it in
the Validate event of a text box:

Private Sub txtZIP_Validate(Cancel As Boolean)
    If IsNumeric(txtZip.Validate) = False then
       MsgBox "Enter a number, stupid!"
       txtZIP.text = ""
    End If
End Sub

One thing to be aware of in cases like Zip codes and Social Security
numbers, though: You'll need to account for things like dashes in a
ZIP+4 number.  IsNumeric("90210") returns True, but
IsNumeric("90210-0101") returns False.

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---



Tue, 30 Oct 2001 03:00:00 GMT  
 Zip Code Number Only?
Thanks,
I totally forgot about the IsNumeric statement.
Thanks alot
Jason

Quote:


> > I can't remember how to make sure a user can't input a letter into a
> number
> > field like zip code.  Please help me.  I'm a VB wannabe.
> > Thanks

> Using the IsNumeric function is probably the easiest way, though it's
> not necessarily the most elegant.  You could, for instance, put it in
> the Validate event of a text box:

> Private Sub txtZIP_Validate(Cancel As Boolean)
>     If IsNumeric(txtZip.Validate) = False then
>        MsgBox "Enter a number, stupid!"
>        txtZIP.text = ""
>     End If
> End Sub

> One thing to be aware of in cases like Zip codes and Social Security
> numbers, though: You'll need to account for things like dashes in a
> ZIP+4 number.  IsNumeric("90210") returns True, but
> IsNumeric("90210-0101") returns False.

> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---



Tue, 30 Oct 2001 03:00:00 GMT  
 Zip Code Number Only?
Also another way of doing the above would be allow only numeric values
to be entered in the the text field for the zip code. Example of the
code that you can write is as follows-

Private Sub txtZipCode_KeyPress(KeyAscii As Integer)
  If Not (KeyAscii = 45 Or (KeyAscii >= 48 And KeyAscii <= 57) Or
KeyAscii = vbKeyBack) Then
    KeyAscii = 0
    Beep
  End If

End Sub
Using the above code you would not allow the user to enter and other
value than the numeric values or "-" to be entered in the text box.

Hope this works.

Gaurav

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---



Tue, 30 Oct 2001 03:00:00 GMT  
 Zip Code Number Only?
    You might also want to look at the Masked Edit control.

--
Paul Parkhurst
Software Engineer

Quote:

>I can't remember how to make sure a user can't input a letter into a number
>field like zip code.  Please help me.  I'm a VB wannabe.
>Thanks



Wed, 31 Oct 2001 03:00:00 GMT  
 Zip Code Number Only?
Check the KeyAscii value within the KeyPress event of the text box:

Sub TxtZIP_KeyPress(KeyAscii As Integer)
    If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub

B-Mann


Quote:
>     You might also want to look at the Masked Edit control.

> --
> Paul Parkhurst
> Software Engineer


> >I can't remember how to make sure a user can't input a letter into a
number
> >field like zip code.  Please help me.  I'm a VB wannabe.
> >Thanks



Wed, 31 Oct 2001 03:00:00 GMT  
 Zip Code Number Only?


Quote:
>    You might also want to look at the Masked Edit control.

>--
>Paul Parkhurst
>Software Engineer


>>I can't remember how to make sure a user can't input a letter into a number
>>field like zip code.  Please help me.  I'm a VB wannabe.
>>Thanks

hi Jason
Try using the keyascii  code on the 'KEy press event....try as follows:-

Say your text box 'name' for inputing is called txt1 then...

Private sub txt1_keypress(keyascii as integer)

if (keyascii >=0 and keyascii <=9) or keyascii = vbkeydecpt or
keyascii=vbkeyback then
Exit sub
Else
Key ascii =0
beep
end if
end sub

Try this code by copying and pasting (dont forget to change your text box
name)..

--
richard



Fri, 09 Nov 2001 03:00:00 GMT  
 Zip Code Number Only?
You could try the following code quite effectively.

Private Sub text1_KeyPress(KeyAscii As Integer)
dim Number as String
Number = "0123456789"

  If InStr(Number, Chr(KeyAscii)) = 0 Then
    KeyAscii = 0
  End If
End Sub

Cheers,
Yossi.


Quote:


> >    You might also want to look at the Masked Edit control.

> >--
> >Paul Parkhurst
> >Software Engineer


> >>I can't remember how to make sure a user can't input a letter into a
number
> >>field like zip code.  Please help me.  I'm a VB wannabe.
> >>Thanks

> hi Jason
> Try using the keyascii  code on the 'KEy press event....try as follows:-

> Say your text box 'name' for inputing is called txt1 then...

> Private sub txt1_keypress(keyascii as integer)

> if (keyascii >=0 and keyascii <=9) or keyascii = vbkeydecpt or
> keyascii=vbkeyback then
> Exit sub
> Else
> Key ascii =0
> beep
> end if
> end sub

> Try this code by copying and pasting (dont forget to change your text box
> name)..

> --
> richard



Sat, 10 Nov 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Standard data entry for Zip Codes and Phone Numbers

2. abcrd001.zip/abc0995.zip - ALL BASIC CODE Packets/Reader/Extractor

3. Need ZIP source code or freeware ZIP DLL

4. ANN: Zip Code/Area Code/Time Zone Data and Components

5. Postal codes and zip codes

6. international post codes (Zip codes) - ricerca tabella codici postali europei per database

7. Ho do I calculate distance based on zip code (stores within distance)

8. validate zip code

9. ZIP files from within Access code

10. Input Mask for Zip Code

11. ZIP CODE DATA

12. USA Zip Code Database

 

 
Powered by phpBB® Forum Software