Locked Writing a Sub

  • Thursday, April 12, 2012 1:05 PM
     
     

    Hello all, I'm having some problems writing a sub. Below are some screen prints

    I made a on screen keyboard using all labels  This app. is for a touch screen. The first pic is the code for all 40 labels using the If Then statement.(Screen print is for Label2 only). Second pic is the Sub I wrote so when you click on anyone of the labels, the labels text appears in the textbox with focus. As you can see the error I keep getting. What in the world am I doing wrong? Thank you for your help.

All Replies

  • Thursday, April 12, 2012 1:09 PM
     
     
    The VB board is here.  This is the T-SQL board.  To answer your question, I bet that the first time a user clicks a label, TextBox1.Text is null.  Because you reference it in the assignment, you pick up a null reference exception.  You should add another branch to your If statement to check if TextBox1.Text is null before you do something.
  • Thursday, April 12, 2012 1:10 PM
     
     Answered Has Code

    Hello

    This is a forum for SQL Server Transact-SQL, not for VB.NET

    And the answer is, you haven't declared & assigned the variable send in sub "LabelClick"; change it this way:

    Private Sub LabelClick(sender as Object)
    ...
    End Sub
    
    Private Sub Label55_Click(sender As Object, e as EventArgs)
        LabelClick(sender)
    End Sub


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing

    • Marked As Answer by bwells59 Thursday, April 12, 2012 1:19 PM
    •  
  • Thursday, April 12, 2012 1:19 PM
     
     
    Thank you Olaf, it works. I think I need to hit the books again. Thanks again. Sorry about the wron forum.
  • Thursday, April 12, 2012 1:26 PM
     
     
    Little tip; to avaoid such mistakes you should set OPION EXPLICIT ON and as it's best also OPTION STRICT ON.

    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing


  • Saturday, April 14, 2012 1:40 PM
     
     
    From your images, the variable "sender" is not define within the LabelClick routine, so I am surprised the code would compile. 
     
    Within the LabelClick subroutine, right-click on the variable "sender" and choose the option "Go to definition".  Show us the line of code that the IDE displays.

    --
    Mike