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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need some help

Status
Not open for further replies.

wishstar

Technical User
Sep 4, 2002
2
US
I am kind of new to programming so this question is probably simple to most of you but I am stumped.
I am writting a program in which the user watches a picture scroll across the screen and then stops in the middle and at this time they must spell what the picture is. Where I have run into a problem is allowing the keyboard input. When the picture gets to the middle of the screen it beeps and you cannot press a key or anything. This is the code I have so far. I have more Cases of pictures but I did not put them here. any help would be greatly appreciated. Thank you

Private Sub Form_Load()
Picture1.Picture = LoadPicture("D:\letter factory\click to start.jpg")
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub text1_KeyPress()
Dim KeyAscii As Integer
If KeyAscii = 65 Then 'waits for letter A to be pressed
Print "" 'prints blank space
Print "" 'prints blank space
Print "" 'prints blank space
Print Spc(5); "A" ' 'moves 5 spaces and then prints letter"

Else
Beep
End If
End Sub
Private Sub Picture1_click()
Dim pic As Picture
Dim X As String
Dim rand As String
Dim keystate As Integer
Randomize Timer
rand = Int(Rnd * 20) + 1
Select Case rand
Case Is = 1
Set pic = LoadPicture("D:\letter factory\pic1.jpg")
Picture1.Picture = pic
X = 9000
Do While X > 5000
Picture1.Move (X)
X = X - 0.1
Loop
Call text1_KeyPress
 
[tt]
'shouldn't it be

Private Sub Text1_KeyPress(KeyAscii As Integer)

End Sub

[/tt]

'????
 
I tried that and when I called it I got an error.
 
Hi Wishstar

I think your problem is with text1_KeyPress. KeyPress is a Event (VB is event driven) but in your code you're calling it like a procedure and , as such, no Event is taking place(e.g. user input). Try commenting out the call to it and let to computer wait for the Event (key stroke) to happen.

Jon
 

If you are going to call a procedure that takes arguments you must supply those arguements. In other words you would need to adjust your call to...
[tt]
Call Text1_KeyPress(65) 'passing in the character code for A

'OR


Text1_KeyPress 65
[/tt]
 
You haven't got an event handler in your code to detect the KeyPress event, and you haven't ensured what has focus to catch the event.

When you are ready for key input (since you don't know where focus will be) set Form.KeyPreview = True then stick your key handling code in the Form_Keydown event Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top