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.
- Moved by Naomi NMicrosoft Community Contributor Thursday, April 12, 2012 1:12 PM Better answer can be here (From:Transact-SQL)
All Replies
-
Thursday, April 12, 2012 1:09 PMThe 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
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 SubOlaf 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 PMThank 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 PMLittle 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- Edited by Olaf HelperMicrosoft Community Contributor Thursday, April 12, 2012 1:26 PM
-
Saturday, April 14, 2012 1:40 PM

