![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
Hi ,
As you know that iam a newbie in visual basic but i had passed a good chapter and now i am tring to make some programs to have the scence of programming .. my present program is a button moving by keyboard ** Descuss : when i press "w" it movies up and "s" down "a" right "d" Left so i made that script in the button ================== On Keypress .. ' "w" Up if keyascii = "NO." then command1.top = top + 1 else end if ' "s" Down if keyascii = "NO." then command1.top = top - 1 else end if ' "a" right if keyascii = "NO." then command1.left = left - 1 else end if ' "d" left if keyascii = "NO." then command1.left = left + 1 else end if =================== But when i did that the button moves one long move and never moves again ,, plz any one help me ![]() Thanx in advance .. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
KeyAscii is an ascii code not a keycode - you'd be better off putting the handler in the Form_KeyDown event. Also, why don't you use a select case statement, and what does "NO." mean?
Remember to set the form's KeyPreview property to true so you catch all events, and also that you're moving in Twips, not pixels, so it would take several presses before you see anything with your original code. I changed the keys to UDLR to make it more obvious Select Case KeyCode Case VbKeyUp Command1.Top = Command1.Top - Screen.TwipsPerPixelY Case VbKeyDown Command1.Top = Command1.Top + Screen.TwipsPerPixelY Case VbKeyLeft Command1.Left = Command1.Left - Screen.TwipsPerPixelX Case VBKeyRight Command1.Left = Command1.Left + Screen.TwipsPerPixelX End Select |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|