Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Key Press

Status
Not open for further replies.

Goodloe

Programmer
Sep 4, 2001
25
US
I created a calculator, and I would like to be able to use
the Operator functions (+ - * / etc) from the keyboard. I
used KeyAscii to enter number digits from the keyboard.

I'm having a problem getting the Operator Functions to work
from the keyboard. Can you help me out? If at all possible
along with your answer can you post an example?
 
use the same principle in the keypress event

if keyascii= '(number for operator) eg /=47 then
'code for dividing etc
end if

works for me

to discover keycodes try putting two textboxes(text1 & text2) on a form and in the keypress event of the first one code
text2.text=keyascii
run the project and type the characters/operators into text1
hope this helps
 
I don't know if this is what you want but here it is.
You can use the "keycode" procedure

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyMultiply or (KeyCode = vbKey8 And Shift = 1) Then
...
end if

end sub

here are the other codes

vbKeyAdd
vbKeySubtract
vbKeyDivide

these are all in VB help under Keycode.
 
Hello, I sent a message earlier today asking how to
program the keyboard Operator Keys(+ - / * etc) to perform
calculations on the calculator I created in VB6. I still can't get it to work, below is a sample of the code I've been using in attempt to get it to work. Do you think you
could provide me with a more detailed example of the code?

Private Sub cmdPlus_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyAdd Then
Operand1 = Val(lbldisplay.Caption)
Operator = "+"
lbldisplay.Caption = ""
End If
End Sub
 
does it matter if you use KEYPRESS or KEYDOWN

if you use KEYDOWN then you can use this code

Private Sub cmdPlus_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyMultiply or (KeyCode = vbKey8 And Shift = 1) Then

Operand1 = Val(lbldisplay.Caption)
Operator = "+"
lbldisplay.Caption = ""

end if

end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top