Problems with KeyPress

  • Thread starter Thread starter Mehul Malhotra
  • Start date Start date
M

Mehul Malhotra

Hi all! I was just messing around with something that I
wrote in VB 6.0 and ran into a problem. In case any you
of you have read my post of boolean, its back to that
same calculator. I wanted to design it in such a way that
if a user presses enter then it takes it as the person
has chosen to use the = sign. The problem is that when
the Form was selected I had pressed enter and now for
some unknown reason, without any code that specifies
whether the key pressed is the Enter key or not, if I
have pressed any button followed by the Enter key, that
same button is pressed again.
The english in that last sentence is quite bad let me
give an example!
If I click on 7 and then press enter the display will
show another 7 in the box which is something that I dont
want.

Any ideas as to how I can get rid of this without having
to do it all over again!!??

Thanks a lot
 
Hi Mehul,
Probably you have somewhere a routine that goes like this in pseudo code

If key = 0 to 9
value = key.value
end if
textbox= oldtextboxvalue + value

To overcome that, start with cleaning the value always or make this

if key = 1 to 9
value = key.value
else
value = 0
end if

I hope I was guessing right and send else some code?

Cor
 
Make sure that Form's KeyPreview property is set to 'True'. Also don't
forget to put e.Handled = True in your Form_Keypress event handler.
 
Back
Top