Ultimate VB noob

matas

Golden Member
Aug 8, 2005
1,518
0
0
so here I am, trying to learn first programming language lol. I have to make this program that I find rather difficult. I have to make a traffic light with three vertical picture boxes that change colors when tab is pressed down. There are 3 picture boxes, and only one color must show at the time, starting with green. When you press tab, green supposed to turn white, and yellow picture box supposed to turn yellow, and when tab is pressed again, yellow should turn white and red picture box turn red. And it should cycle like that. How do I bind Tab key?
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Private Sub Form1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyTab Then
# Color changing logic
End If
End Sub

EDIT: Wow I haven't touched VB6 in years. I'm surprised I remembered that...
 

matas

Golden Member
Aug 8, 2005
1,518
0
0
It does not seem to respond when I press Tab. I figured out that GotFocus works when tab is pressed down. But I'm not sure how to make this changing sequence to work.
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126

IIRC you have to set the form property KeyPreview = True on your form in the designer so the keypress event happens..
 

matas

Golden Member
Aug 8, 2005
1,518
0
0
I need help now with sub procedures. Program that adds three numbers from three text boxes and averages them out. I know how to do it regularly but I'm not sure how to do a sub procedure and not sure what does that 'call' mean. Any help?