r/visualbasic • u/DJSETBL • Sep 10 '21
VB.NET Help Zero References to Sub
I am very new to Visual Basic and am finding that my code is not being referenced in the designer view at all. I am trying to get it to change the forecolor when i press tab then move to the next box, simulating a traffic light. I am almost certain it's not quite right but I cant fix it without being able to refence the code. Any help would be appreciated.
2
u/TheFotty Sep 10 '21
The 0 references thing is a little misleading, because it doesn't count references to the sub made by using the handles (Handles txtGreenLight.KeyPress) clause which you are using (and is normal and fine to use). I actually brought this exact thing up to the VB dev team once when I was at a conference with them, and they said that since the handles clause is part of the sub definition, it simply doesn't count as a reference to that sub. One could argue that one way or the other, but it doesn't really matter as this is just how it will always be.
The tab key does not fire the keypress event on a textbox, so if that is what you are hitting to go from box to box, this code will never fire since tab won't raise the event. The only keypress event that will fire when tab is pressed is going to be the PreviewKeyDown of the textbox control.
2
u/MarkJay8 Sep 10 '21
You should use the Enter event or the Leave event of the TextBox and set the ForeColor property of the TextBox
1
u/RJPisscat Sep 10 '21
That's a good suggestion, especially since there is a code sample that basically tells the student how to do this assignment.
u/DJSETBL has the instructor told you about docs.microsoft.com? The documentation on Control.Enter and Control.Leave are quite similar to the code you've written and that will help with the details on u/MarkJay8's comment.
1
u/RJPisscat Sep 10 '21
πto what u/TheFotty said.
Is there a reason you can't use RadioButton instead of Textbox? Then you can handle the RadioButton.CheckedChanged Event.