JohnM
Well-known member
TxtBox enter event [RESOLVED]
I would appreciate your help on this. I can't believe I can't see the error in this code. I'm new at VB but I didn't think I would miss this. I have been looking at this for a few hours.. I just can't see the error.
I have a button that when clicks sends the focus to this textbox (txbMPG). But when I enter a value in this txbMPG, it acts as if the ENTER event has already happened. It allows me to enter a value, but when I hit enter, I get a beeping sound. I put in that Messagebox to see the timing of the ENTER routine. The message box turns on when the focus is put on the TxbMPG, so it looks like the ENTER event of the txbMPG is triggered when the textbox txbMPG gets focus.
I need it to trigger the enter when I hit the ENTER button for the txbMPG not when the focus on the txbMPG is triggered.
I appreciate very much your time on looking at this.
PrivateSub txbMPG_Enter(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txbMPG.Enter
y8 = CInt(Val(txbMPG.Text))
If y8 <> 0 Then
btnCalculateGas.Focus()
Else
MessageBox.Show("ENTERING Y8 equals..." & y8, "value of y8")
txbMPG.Focus()
EndIf
EndSub
I would appreciate your help on this. I can't believe I can't see the error in this code. I'm new at VB but I didn't think I would miss this. I have been looking at this for a few hours.. I just can't see the error.
I have a button that when clicks sends the focus to this textbox (txbMPG). But when I enter a value in this txbMPG, it acts as if the ENTER event has already happened. It allows me to enter a value, but when I hit enter, I get a beeping sound. I put in that Messagebox to see the timing of the ENTER routine. The message box turns on when the focus is put on the TxbMPG, so it looks like the ENTER event of the txbMPG is triggered when the textbox txbMPG gets focus.
I need it to trigger the enter when I hit the ENTER button for the txbMPG not when the focus on the txbMPG is triggered.
I appreciate very much your time on looking at this.
PrivateSub txbMPG_Enter(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txbMPG.Enter
y8 = CInt(Val(txbMPG.Text))
If y8 <> 0 Then
btnCalculateGas.Focus()
Else
MessageBox.Show("ENTERING Y8 equals..." & y8, "value of y8")
txbMPG.Focus()
EndIf
EndSub
Last edited by a moderator: