Results 1 to 3 of 3

Thread: Chr() - Very weird [Resolved]

  1. #1

    Thread Starter
    Lively Member UTGrim's Avatar
    Join Date
    Jan 2005
    Location
    Brazil
    Posts
    92

    Resolved Chr() - Very weird [Resolved]

    I'm making a calculator that receives input through the form's KeyUp event. I created a Select Case to know what characters were input like this:

    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2. Select Case Chr(KeyCode)
    3.     Case "0"

    This works fine when I type with the numbers on top of the letter keys, but when I use the numbers to the right of the keyboard, Chr() returns some weird characters, like 96 (`).

    How can I know what characters were typed down for real?

    Thank you.
    Last edited by UTGrim; Apr 24th, 2005 at 10:33 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Chr() - Very weird

    You will have to select case on all possible key codes and since the number above the letter keys are different
    keys from the number pad. You might try the KeyPres event since its parameter is KeyAscii and not the actual
    key but its equilivalent ascii character code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Chr() - Very weird

    This comes from a working pgm.
    It is in the Form's Keydown event.
    It will detect the normal digit keys, and the numeric keypad keys.
    VB Code:
    1. Select Case KeyCode
    2.     Case Asc("0"), 96
    3.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 0
    4.     Case Asc("1"), 97
    5.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 1
    6.     Case Asc("2"), 98
    7.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 2
    8.     Case Asc("3"), 99
    9.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 3
    10.     Case Asc("4"), 100
    11.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 4
    12.     Case Asc("5"), 101
    13.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 5
    14.     Case Asc("6"), 102
    15.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 6
    16.     Case Asc("7"), 103
    17.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 7
    18.     Case Asc("8"), 104
    19.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 8
    20.     Case Asc("9"), 105
    21.       lblQuickLeadAccess.Caption = lblQuickLeadAccess.Caption & 9
    22.     End Select
    Rob C

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