Results 1 to 7 of 7

Thread: [RESSURECTED] Keypress and indicies

  1. #1

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    [RESSURECTED] Keypress and indicies

    I am using this code:
    VB Code:
    1. Public Sub form_keypress(KeyAscii As Integer)
    2. If KeyAscii = Chr(97) Then
    3. Call englow_Click(11)
    4. End Select
    5. End Sub
    and "englow" has the following code:
    VB Code:
    1. Private Sub englow_Click(Index As Integer)
    2. Text1.Text = Text1.Text + englow(Index).Caption
    3. 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.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Keypress and indicies

    This works. I don't understand the problem:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click(Index As Integer)
    4.   MsgBox "a pressed"
    5.   Text1.Text = Command1(Index).Caption
    6. End Sub
    7.  
    8. Private Sub Form_Load()
    9.   Text1.Text = ""
    10. End Sub
    11.  
    12. Private Sub Text1_KeyPress(KeyAscii As Integer)
    13.   If KeyAscii = Asc("a") Then
    14.     Command1_Click (0)
    15.     KeyAscii = 0
    16.   End If
    17. End Sub

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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:
    1. Public Sub form_keypress(KeyAscii As Integer)
    2.    Select Case KeyAscii
    3.         Case 97 'lowercase a
    4.            englow(11).Value = True
    5.         Case 98 'lowercase b
    6.            englow(12).Value = True
    7.    End Select
    8. End Sub

  4. #4

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: Keypress and indicies

    I solved it with this:
    VB Code:
    1. Select Case KeyAscii
    2.         Case 97
    3.            Call englow_Click(11)
    4.         Case 98
    5.            Call englow_Click(5)
    6.    End Select
    Thanks

  5. #5

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: [RESSURECTED] Keypress and indicies

    ok, I have a similar problem:
    VB Code:
    1. Public Sub form_keypress(KeyAscii As Integer)
    2. Dim i As Integer
    3. For i = 97 To 122
    4.     If KeyAscii = Chr(i) Then
    5.         Call low_Click(i)
    6.     End If
    7. Next
    8. End Sub
    Why wont it call low_click?

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESSURECTED] Keypress and indicies

    Keyascii is a number, not a letter

    VB Code:
    1. If KeyAscii = i Then

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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
  •  



Click Here to Expand Forum to Full Width