it's my first post. Could you give me some tips which code is better and why? Mainly those two codes do the same, but using other methods. Cheers
FIRST CODE
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Age.Click
Dim age As Integer
Dim boxinput As String
boxinput = InputBox("Please input your age", "Age input", "28")
Try
age = boxinput
Catch ex As Exception
If boxinput = "" Then
MessageBox.Show("You clicked cancel!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
Else
MessageBox.Show("Correct your age!" & Environment.NewLine & "Input number only!")
End If
End Try
End Sub
SECOND CODE
Private Sub Age2_Click(sender As Object, e As EventArgs) Handles Age2.Click
Dim age As Integer
Dim boxinput As String
boxinput = InputBox("Please input your age", "Age input", "28")
If boxinput = "" Then
MessageBox.Show("You clicked cancel!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
ElseIf IsNumeric(boxinput) Then
age = CInt(boxinput)
Else
MessageBox.Show("Correct your age!" & Environment.NewLine & "Input number only!")
End If
End Sub