|
-
Dec 13th, 2005, 02:43 PM
#1
Thread Starter
Addicted Member
[RESSURECTED] Keypress and indicies
I am using this code:
VB Code:
Public Sub form_keypress(KeyAscii As Integer)
If KeyAscii = Chr(97) Then
Call englow_Click(11)
End Select
End Sub
and "englow" has the following code:
VB Code:
Private Sub englow_Click(Index As Integer)
Text1.Text = Text1.Text + englow(Index).Caption
End Sub
As you can see, there are more than one "englow" buttons. 49 of them in fact. When I press a button on my keyboard (say a, with the ascii value 97), I want it to call just a certain englow button. Is what i'm trying to do impossible, and i should change the names of the buttons, or is there a way around this?
Thanks in advance
Last edited by ajames; Dec 13th, 2005 at 03:54 PM.
-
Dec 13th, 2005, 03:02 PM
#2
Re: Keypress and indicies
This works. I don't understand the problem:
VB Code:
Option Explicit
Private Sub Command1_Click(Index As Integer)
MsgBox "a pressed"
Text1.Text = Command1(Index).Caption
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc("a") Then
Command1_Click (0)
KeyAscii = 0
End If
End Sub
-
Dec 13th, 2005, 03:25 PM
#3
Re: Keypress and indicies
First, this If statement will never be True
If KeyAscii = Chr(97)
Pass the Buttons' Index to the click event as shown by dglienna Or cause the button to be "clicked" using the Value property. This will fire the buttons click event with the proper index.
VB Code:
Public Sub form_keypress(KeyAscii As Integer)
Select Case KeyAscii
Case 97 'lowercase a
englow(11).Value = True
Case 98 'lowercase b
englow(12).Value = True
End Select
End Sub
-
Dec 13th, 2005, 03:31 PM
#4
Thread Starter
Addicted Member
Re: Keypress and indicies
I solved it with this:
VB Code:
Select Case KeyAscii
Case 97
Call englow_Click(11)
Case 98
Call englow_Click(5)
End Select
Thanks
-
Dec 13th, 2005, 03:54 PM
#5
Thread Starter
Addicted Member
Re: [RESSURECTED] Keypress and indicies
ok, I have a similar problem:
VB Code:
Public Sub form_keypress(KeyAscii As Integer)
Dim i As Integer
For i = 97 To 122
If KeyAscii = Chr(i) Then
Call low_Click(i)
End If
Next
End Sub
Why wont it call low_click?
-
Dec 13th, 2005, 03:59 PM
#6
Re: [RESSURECTED] Keypress and indicies
Keyascii is a number, not a letter
-
Dec 13th, 2005, 03:59 PM
#7
Re: [RESSURECTED] Keypress and indicies
You know what I would do? I would set Index for each button that corresponds to actual ascii code (say upper case char) so you can use real time Keyascii value to call appropriate button's click. Let me know if you need more info on this.
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
|