Visual Basic 2005


Add to MY Favorites...

Back to Vicky's Home Page Teaching Home Page Visual Basic 2005 Html For Kids

Data Validation 

Validating user input for acceptable content is a good thing to do.  The best practice would be a combination of the MaskedTextBox, which is set up to receive input in a specific format and If..then..elseif..else statement, which determines if the data is reasonable.  The Case structure could also be used for determining data reasonability.

 

If..then..elseif..else

 

For data validation, you would have an If, then a number of ElseIfs looking for all possible incorrect entries.  The final Else is what is done if the validation routine finds the input data falls within an acceptable range.  In this case, it is looking for k-12 aged children, who must be between the ages of 5 and 18.  It does not determine if the data is accurate.  It only determines if it is reasonable. 

If age >=19 then

label1.text = “number must be less than 19”

ElseIF Score <=5 then

     Label1.text = “number must be greater than 4”

Else

     Label1.text = “This number is within range”

End if

 

MaskedTextBox

The MaskedTextBox limits the type of data entered.  It does not determine reasonability.

This is a tool in the ToolBox.  One of the properties is Mask.  Clicking the Mask property gives you a window to make mask selections from.  The mask provides a data entry format with any punctuation filled in automatically.  The data type can be validated on input, so that letters cannot be entered for a numeric item, or number not entered for a text item.

Even though the Validating Type is shown as (none) for Social security number, only numbers are accepted into the textbox.

A mask selection can also be made by right clicking the VERY small drop down listbox arrow that appears in the upper right hand corner of the MaskedTextBox once it is in the form.

This tool does not determine if the data entered is accurate or within reasonable limits.  It only insures that the data is the correct type.

 

 


 
Another page developed by
vicky@vickywoodard.com
Copyright © 2006 Vicky K. Woodard
All rights reserved
Last updated: 8/17/2006