Results 1 to 6 of 6

Thread: What this code mean ???

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Location
    Kuwait
    Posts
    10

    Question What this code mean ???

    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 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,

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    CType() converts the first argument to the type of data specified by the second argument
    \m/\m/

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: What this code mean ???

    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 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.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 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,
    the object that raises the event is the sender .In your case , I think it's textbox object .

    your now converting the expression into TextBox data type object "text".

    this example explain it more :
    VB Code:
    1. Dim dic As Decimal = 1.002
    2. Dim byt As Byte
    3. byt = CType(dic, Byte)
    4. MsgBox(byt.ToString)

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    too late......

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Location
    Kuwait
    Posts
    10
    Thanks alot now it's clear to me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width