|
-
Jul 18th, 2001, 04:08 AM
#1
Thread Starter
Fanatic Member
Calculator Program
Hi,
I found a small calculator program in the MSDN samples
called CALC.
I need to change it, because I need 2 result displays.
We need that stupid Euro you see.
Instead of using the mouse I want to use the numeric keypad
keys so I changed the program by putting the key codes.
The problem I have is that I can use the numeric and the
operator keys, but the enter key won't work.
I use the vbKeySeparator Key Code for activating the '=' key
but it won't work.
When using the mouse and clicking the '=' button all works
fine.
Is there someone who could help me with this or maybe
someone have a source of the windows calculator program.
thanx
Ray
-
Jul 18th, 2001, 04:16 AM
#2
-= B u g S l a y e r =-
I'm not sure what u mean, could you post some sample code ?
-
Jul 18th, 2001, 04:36 AM
#3
Thread Starter
Fanatic Member
Hi peet,
The problem is simple.
If you start the calculator program in windows, than you
can use either the mouse or the numeric pad buttons.
If you have the MSDN library then there'is in the sample
directory an application called CALC written by microsoft.
That works only with the mouse so I changed it for using also
the numeric key pad.
All buttons are working, 0 to 9, the +,-,* and / also.
The "=" key don't exists so I need to use the numeric
pad enter key for simulating the '=' key.
It is called vbKeySeparator so when I press the enter key
I translate it to operator '='.
And here it goes wrong, the application ignores the vbKeySeparator check and I don't know why.
cheers
Ray
-
Jul 18th, 2001, 04:44 AM
#4
Thread Starter
Fanatic Member
Peet,
Here the calc source code.
Maybe you find the error.
thanx
Ray
-
Jul 18th, 2001, 05:09 AM
#5
-= B u g S l a y e r =-
hohohoooo... look what i found in the MSDN : chekc article Q188550
it should explain your problems i think
-
Jul 18th, 2001, 05:19 AM
#6
Fanatic Member
or else you could trap either keycodes 13 (enter) or 187 (=) in the form keydown event
-
Jul 18th, 2001, 05:28 AM
#7
Thread Starter
Fanatic Member
peet
can't find the article, can you explain?
rudvs2
Isn't working either.
I think the problem lies on the form focus.
For some reason I lose the form focus so the Keyup procedure
hasn't been called.
Ray
-
Jul 18th, 2001, 05:46 AM
#8
-= B u g S l a y e r =-
ok, here goe's...
MSDN
BUG: vbKeySeparator Constant Does Not Work
Q188550
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions for Windows, version 4.0
--------------------------------------------------------------------------------
SYMPTOMS
When using the constant vbKeySeparator to evaluate keystrokes in the KeyUp, KeyDown, or KeyPress event, the comparison always returns False.
CAUSE
The Visual Basic documentation lists a keycode constant of vbKeySeparator. The value of this constant is 108 (0x6C) and that value corresponds to the ENTER key on the Numeric Keypad. It also lists the constant vbKeyReturn that has the value 13 (0xD) and corresponds to the ENTER key on the Keyboard. In the KeyDown, KeyPress, or KeyUp events, the keycode returned is 13 regardless of which ENTER key is pressed. A test to see if the keycode is equal to 108 will always return False because 13 is obviously not equal to 108. The result is that there is no way to determine which ENTER key was depressed.
RESOLUTION
It is possible to differentiate between the two ENTER keys using the Win32 API PeekMessage. A bitwise comparison can then be made to determine which of the ENTER keys was pressed.
WORKAROUND
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Add the following code to Form1:
Code:
Private Declare Function PeekMessage Lib "user32" Alias _
"PeekMessageA" (lpMsg As MSG, ByVal hwnd As Long, _
ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, _
ByVal wRemoveMsg As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Const PM_NOREMOVE = &H0
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_RETURN = &HD
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim MyMsg As MSG, RetVal As Long
' pass:
' MSG structure to receive message information
' my window handle
' low and high filter of 0, 0 to trap all messages
' PM_NOREMOVE to leave the keystroke in the message queue
' use PM_REMOVE (1) to remove it
RetVal = PeekMessage(MyMsg, Me.hwnd, 0, 0, PM_NOREMOVE)
' now, per Q77550, you should look for a MSG.wParam of VK_RETURN
' if this was the keystroke, then test bit 24 of the lparam - if ON,
' then keypad was used, otherwise, keyboard was used
If RetVal <> 0 Then
If MyMsg.wParam = VK_RETURN Then
If MyMsg.lParam And &H1000000 Then
MsgBox "Enter from Keypad pressed"
Else
MsgBox "Enter from Keyboard pressed"
End If
End If
Else
MsgBox "No message waiting, or possible problems calling PeekMessage"
End If
End Sub
Run the project and press on both ENTER keys. You will get a message box correctly identifying which ENTER key was pressed.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
Steps to Reproduce Behavior
Start a new Standard EXE project in Visual basic. Form1 is created by default.
Add the following code to Form1.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyReturn
MsgBox "KeyCode 13. Keyboard Enter Key Pressed."
Case vbKeySeparator
MsgBox "KeyCode 108. NumPad Enter Key Pressed."
End Select
End Sub
Run the project and press both ENTER keys. Note that the KeyCode is 13 regardless of which ENTER key is pressed.
REFERENCES
For a more detailed explanation of this bitwise comparison, please see the following article in the Microsoft Knowledge Base:
Q77550 Differentiating Between the Two ENTER Keys
Additional query words: kbDSupport kbDSD kbVBp kbvbp400bug kbVBp500bug kbVBp600bv kbKeyIn kbHook
Keywords : kbGrpVB
Issue type : kbbug
Technology :
Last Reviewed: February 2, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.
-
Jul 18th, 2001, 05:46 AM
#9
Fanatic Member
try this code
VB Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case Is = vbKeyNumpad0
Number_Click 0
Case Is = vbKeyNumpad1
Number_Click 1
Case Is = vbKeyNumpad2
Number_Click 2
Case Is = vbKeyNumpad3
Number_Click 3
Case Is = vbKeyNumpad4
Number_Click 4
Case Is = vbKeyNumpad5
Number_Click 5
Case Is = vbKeyNumpad6
Number_Click 6
Case Is = vbKeyNumpad7
Number_Click 7
Case Is = vbKeyNumpad8
Number_Click 8
Case Is = vbKeyNumpad9
Number_Click 9
Case Is = vbKeyDivide
Operator_Click 0
Case Is = vbKeyAdd
Operator_Click 1
Case Is = vbKeyMultiply
Operator_Click 2
Case Is = vbKeySubtract
Operator_Click 3
Case Is = 187
Operator_Click 4
Case Is = vbKeyEnd
cmdStop_Click
Case Is = 13
Operator_Click 4
End Select
End Sub
-
Jul 18th, 2001, 06:22 AM
#10
Thread Starter
Fanatic Member
peet
Thanx peet now I can solve the problem.
rudvs2
Your code works only when I put a text control on
the form and set the focus on the text control.
Regarding the article from peet the vbKeySeparator
or code 187 don't work.
thanx both for your help
Ray
-
Jul 18th, 2001, 06:24 AM
#11
-= B u g S l a y e r =-
any time Ray
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|