Labactivity 13 Inputvalidationandexceptionhandling
Labactivity 13 Inputvalidationandexceptionhandling
MULTIMEDIA CONCEPT
Lab Practical 13
Centre for Diploma Studies Page 2/7
Department of Information Technology Session 2023/2024
Lab Practical Title: Input Validation and Exception Semester 2
Handling
Learning Outcome(s)
At the end of this practical session, you should be able to:
1. Write a VB code for input validation
2. Write a code with exception handling application development.
Solution 13.1:
Step 1: Design a Form and Step 2: Set the Properties
i. Create a Windows VB.NET application and design the form to resemble Figure 7.9.
ii. Add a tooltip in your design
End If
Else
tt.Show("Insert your name", txtName, New Point(0, -40), 4000)
txtName.Focus() 'Return Focus
End If
End Sub
'Something Typed In
If Not String.IsNullOrEmpty(strPhoneNum) Then
'Check Validity
PhoneValid = rePhone.IsMatch(strPhoneNum)
End If
End Function
End If
End If
End Sub
End Sub
End Sub
Else
AgeValid = True
End If
Next
End If
End Sub
'Yes It Is
MessageBox.Show("All data Submitted Correctly")
End If
End Sub
End If
Next tText
End Sub
2/ = Answer
Calculat
Solution 13.2:
Centre for Diploma Studies Page 7/7
Department of Information Technology Session 2023/2024
Lab Practical Title: Input Validation and Exception Semester 2
Handling
Step 1: Design a Form and Step 2: Set the properties for each object controls
i. Create a new web application project
ii. In a new web form, add the suitable objects and set its properties
Step 4: Run the program and fix the error (if occurred)
i. Run using Start button available at the Microsoft Visual Studio tool bar
ii. Key in the number 0 at the textbox through textbox and click button ‘Calculate’
iii. What an error occurred?
iv. Modify your event procedure by add exception handling structure as below:
Try
lblAnswer.Text = 2 \ txtNumber.Text 'Code to be executed
Catch ex As Exception
MessageBox.Show(ex.ToString())'Error resolution code
Finally
MessageBox.Show("finally block executed") 'Cleanup code
End Try