Re: What this code mean ???
Quote:
Originally posted by Roomi7
Private Sub txtName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFirstName.Validating, txtLastName.Validating
If CType(sender, TextBox).Text = "" Then
MessageBox.Show("You must enter a first and last name.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning)
e.Cancel = True
End If
End Sub
I write this code from the book and it's work :rolleyes: but I don't know what I wrote??
What is ...
1 - CType mean?
2 - Sender mean?
3 - TextBox mean? (My TextBox name is txtFirstName why I use TextBox not txtFirstName?)
Thanks all,
question 1 was answered :)
3 was answered too: The second argument of ctype gets the type of the object, which is TextBox. That's why you use that
2 -> sender is the object that has fired this event. So if txtFirstName fired a Validating event the sender object would be txtFirstName. If txtLastName fired the event, then sender would be txtLastName.