Results 1 to 3 of 3

Thread: On key press, multiple cases

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    5

    On key press, multiple cases

    I want it so that for each case you will have to press a key, for example

    Case 1 - You have to press "I"
    Case 2 - You have to press "V"

    etc, thanks!

    Code:
    1. Private Sub imgButton_Click(Index As Integer)
    2. Dim Buffer As clsBuffer
    3. Dim i As Long
    4.    
    5.     ' If debug mode, handle error then exit out
    6.     If Options.Debug = 1 Then On Error GoTo errorhandler
    7.    
    8.     Select Case Index
    9.         Case 1
    10.             If Not picInventory.Visible Then
    11.                 ' show the window
    12.                 picInventory.Visible = True
    13.                 picCharacter.Visible = False
    14.                 picSpells.Visible = False
    15.                 picOptions.Visible = False
    16.                 picParty.Visible = False
    17.                 Picture5.Visible = True
    18.                 BltInventory
    19.                 ' play sound
    20.                 PlaySound Sound_ButtonClick
    21.             Else
    22.                 Picture5.Visible = False
    23.             End If
    24.         Case 2
    25.             If Not picSpells.Visible Then
    26.                 ' send packet
    27.                 Set Buffer = New clsBuffer
    28.                 Buffer.WriteLong CSpells
    29.                 SendData Buffer.ToArray()
    30.                 Set Buffer = Nothing
    31.                 ' show the window
    32.                 picSpells.Visible = True
    33.                 picInventory.Visible = False
    34.                 picCharacter.Visible = False
    35.                 picOptions.Visible = False
    36.                 picParty.Visible = False
    37.                 Picture5.Visible = True
    38.                 ' play sound
    39.                 PlaySound Sound_ButtonClick
    40.             Else
    41.                 Picture5.Visible = False
    42.             End If
    43.         Case 3
    44.             If Not picCharacter.Visible Then
    45.                 ' send packet
    46.                 SendRequestPlayerData
    47.                 ' show the window
    48.                 picCharacter.Visible = True
    49.                 picInventory.Visible = False
    50.                 picSpells.Visible = False
    51.                 picOptions.Visible = False
    52.                 picParty.Visible = False
    53.                 Picture5.Visible = True
    54.                 ' play sound
    55.                 PlaySound Sound_ButtonClick
    56.                 ' Render
    57.                 BltEquipment
    58.                 BltFace
    59.             Else
    60.                 Picture5.Visible = False
    61.             End If
    62.         Case 4
    63.             If Not picOptions.Visible Then
    64.                 ' show the window
    65.                 picCharacter.Visible = False
    66.                 picInventory.Visible = False
    67.                 picSpells.Visible = False
    68.                 picOptions.Visible = True
    69.                 picParty.Visible = False
    70.                 Picture5.Visible = True
    71.                 ' play sound
    72.                 PlaySound Sound_ButtonClick
    73.             Else
    74.                 Picture5.Visible = False
    75.             End If
    76.         Case 5
    77.             SendTradeRequest
    78.         Case 6
    79.             ' logoutGame
    80.             If Not picParty.Visible Then
    81.                 ' show the window
    82.                 picCharacter.Visible = False
    83.                 picInventory.Visible = False
    84.                 picSpells.Visible = False
    85.                 picOptions.Visible = False
    86.                 picParty.Visible = True
    87.                 Picture5.Visible = True
    88.                 ' play sound
    89.                 PlaySound Sound_ButtonClick
    90.             Else
    91.                 Picture5.Visible = False
    92.             End If
    93.     End Select
    94.    
    95.     ' Error handler
    96.     Exit Sub
    97. errorhandler:
    98.     HandleError "imgButton_Click", "frmMain", Err.Number, Err.Description, Err.Source, Err.HelpContext
    99.     Err.Clear
    100.     Exit Sub
    101. End Sub

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: On key press, multiple cases

    You mean something like this:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_KeyPress(KeyAscii As Integer)
    4.     If (KeyAscii = Asc("A")) Or (KeyAscii = Asc("a")) Then  '~~~ Check if the pressed key is "A" or "a"
    5.         MsgBox "You pressed 'A' "
    6.     End If
    7. End Sub
    8.  
    9. Private Sub Form_Load()
    10.     '~~~ This needs to be made TRUE inorder to work
    11.     Me.KeyPreview = True
    12. End Sub

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: On key press, multiple cases

    If I understand you correctly, you want certain keystrokes to simulate a imgButton_Click event, where "I" is equivalent to clicking on imgButton(1), etc?

    If so, then another option is to provide a menu with Ctrl+keys. The menu might be called "View" with submenu items for Inventory, Spelling, Character, Options, etc. With each menu item, you can set the shortcut for it. Suggestion, if using menus for other things, do not use menu keys common to most typical menu items (File, Edit, etc) for those submenu items; i.e., don't use Ctrl+V as that is known world-wide for a Paste shortcut & used in textboxes.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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