Results 1 to 4 of 4

Thread: KeyDown Event

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Seattle, WA, USA
    Posts
    46

    Post KeyDown Event

    Hi, I am writing a program using the keydown event. It works great except I can not get it to send the number keys and other keys like, space, enter, shift, etc. to my text file? Why, would it send letters and not numbers. An example of my code follows:

    Code:

    Private Sub Form_KeyDown(keycode As Integer, Shift As Integer)

    If keycode = 54 Then
    Dim ggFile As Integer
    ggFile = FreeFile
    Open "C:\Log.txt" For Append As ggFile
    Print #ggFile, "6";
    Close ggFile
    End If

    Also, When I make the program Invisible it will not send any keys to the file.
    Thanks,

    Kevin

    Edited by kevdog on 02-27-2000 at 02:02 AM

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    To send the all the number keys this is what I do:

    Private Sub Form_KeyDown(keycode As Integer, Shift As Integer)
    Dim strChr as String
    strChr = KeyAscii
    If strChr => 0 and strChr <= 9 then
    'Dosomething
    endif
    end sub

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Seattle, WA, USA
    Posts
    46

    Post

    It won't work for me, it give me a runtime error 13. This is my current code, Please Help.

    Code:


    Private Sub Form_KeyDown(keycode As Integer, Shift As Integer)
    Dim strChr As String
    strChr = KeyAscii
    If strChr >= 0 And strChr <= 9 Then
    Open "C:\Log.txt" For Append As strChr
    Print #strChr, ;
    Close strChr
    End If
    End Sub



    Thanks,

    Kevin

  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Try to replace
    Code:
    strChr = KeyAscii
    with
    Code:
    strChr = KeyCode
    HTH

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