field validation and input checking 
Author Message
 field validation and input checking

Hi,

I am new to VB 5.0 coming from Pascal.  I am just
getting the hang of the object oriented concept and
have a question related to a project that I am
working on.

I am interefacing with an access database and have
used the forms wizard to generate data input forms.

The problem I am having is when a user does the
following or something similar.  User inputs a
string value where the form is expecting a number.  
Of course the program chokes and crashes.  I know I
need to add a routine to check the contents of the
textbox before the data from the form gets written
to the database.  In pascal I would have just
written an input routine procedure.  

My question is does Visual Basic have built in
routines to do this or must I write some code for
each text box?

Any help appreciated.

Brendin



Tue, 29 Feb 2000 03:00:00 GMT  
 field validation and input checking


says...

Quote:
>The problem I am having is when a user does the
>following or something similar.  User inputs a
>string value where the form is expecting a number.  
>Of course the program chokes and crashes.  I know I
>need to add a routine to check the contents of the
>textbox before the data from the form gets written
>to the database.  In pascal I would have just
>written an input routine procedure.  

>My question is does visual basic have built in
>routines to do this or must I write some code for
>each text box?

>Any help appreciated.

>Brendin

To my knowledge, VB has no auto check capability. I've always called something
like this in each text box's keypress event where I wanted only numbers:

Public Sub sbrNumericValidation(KeyAscii)
      '**********************************************************
      'This Procedure validates numeric fields
      '**********************************************************

        If (KeyAscii >= Asc("0")) And (KeyAscii <= Asc("9")) Then
                Exit Sub
        Else
            KeyAscii = 0
        End If

End Sub

This can be embellished to allow signs and backspace keys, etc.

R,
Mike



Tue, 29 Feb 2000 03:00:00 GMT  
 field validation and input checking



Quote:
> Hi,

> I am new to VB 5.0 coming from pascal.  I am just
> getting the hang of the object oriented concept and
> have a question related to a project that I am
> working on.

> I am interefacing with an access database and have
> used the forms wizard to generate data input forms.

> The problem I am having is when a user does the
> following or something similar.  User inputs a
> string value where the form is expecting a number.  
> Of course the program chokes and crashes.  I know I
> need to add a routine to check the contents of the
> textbox before the data from the form gets written
> to the database.  In pascal I would have just
> written an input routine procedure.  

> My question is does visual basic have built in
> routines to do this or must I write some code for
> each text box?

> Any help appreciated.

> Brendin

If you are using bound controls, the data control object has
a validate event that gets triggered when you move from one
record to another, delete the current record or close the
recordset.  You can place checks for all the controls in
the event.

I also have placed in the LostFocus event of a text box code such
as:
    if( IsNumeric(txtText) = False ) then
       msgbox "ERROR..."
       txtText.SetFocus
    endif

This keeps you from having to check every character with
KeyAscii = Asc(1),KeyAscii = Asc(2), etc,etc,etc.

Hope that helps a little.

Chris Garland



Tue, 29 Feb 2000 03:00:00 GMT  
 field validation and input checking

Quote:
>The problem I am having is when a user does the
>following or something similar.  User inputs a
>string value where the form is expecting a number.
>Of course the program chokes and crashes.  I know I
>need to add a routine to check the contents of the
>textbox before the data from the form gets written
>to the database.  In pascal I would have just
>written an input routine procedure.

>My question is does visual basic have built in
>routines to do this or must I write some code for
>each text box?

>Any help appreciated.

>Brendin

    Visual Basic has no build in functionality for this, but there are many
ways achieve it. one of my favorites is to use instr in the KeyPress Event.

    if instr("0123456789", chr$(KeyAscii) = 0 then KeyAscii = 0

and if you wanted to ad "."'s and "-"'s you just do..

    if instr("0123456789-.", chr$(KeyAscii) = 0 then KeyAscii = 0

of course there are many ways. I think the fasted method is to use and OR
with some crazy logic gate.

--jc



Tue, 29 Feb 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Field Validation or Input checking

2. check input field, only numbers accepted

3. Passing the validated fields value to custom method in a field level validation

4. Problems with a user input data validation module

5. How to implement validation input ??

6. Need suggestions for input validation

7. input validation

8. Using Keypress event for input validation

9. Text input and validation just like Win95/98 IP address entry

10. Input Validation Help

11. User Input Validation

12. Form input validation international phone number

 

 
Powered by phpBB® Forum Software