Professional Documents
Culture Documents
Use Tryparse To Validate User Input: Computer Programming I
Use Tryparse To Validate User Input: Computer Programming I
Use Tryparse To Validate User Input: Computer Programming I
COMPUTER PROGRAMMING I
Objective/Essential Standard
Essential Standard
6.00 Apply tools to obtain and validate user input.
Indicator
6.03 Apply Procedures for Validation of User Input.
(3%)
Validating Numeric Input
Method
TryParse (String, Int16) Converts the string representation of a number
to its 16-bit signed integer equivalent. A
Boolean return value indicates whether the
conversion succeeded or failed (true or false).
blnResult true
intNum = 5
Int32.TryParse
blnResult false
intNum = 0
Double.TryParse
blnResult true
dblnum 5.0
Double.TryParse
blnResult false
dblnum 0
Using the Convert Class Methods with Try/Catch
strNum = txtInput.Text
End Sub
Conclusion