Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 11th, 2005, 8:19 PM   #1
ASHORY
Programmer
 
ASHORY's Avatar
 
Join Date: Dec 2004
Location: Egypt
Posts: 30
Rep Power: 0 ASHORY is on a distinguished road
Send a message via ICQ to ASHORY Send a message via MSN to ASHORY Send a message via Yahoo to ASHORY
Exclamation Moving Object ... Question .

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 ..
__________________
"^Ahmed.SHOukRY^"
http://www.ashory.741.com
ASHORY is offline   Reply With Quote
Old Mar 14th, 2005, 3:17 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC