CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    30

    URGENT!!pls Help Me!!

    z
    Last edited by kogan31; October 6th, 2003 at 07:33 AM.

  2. #2
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,900
    My KeyDown Event looks like this

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

    End Sub


    I guess you must be using another type of VB system.

    Could it perhaps be VB.NET?

    HOWEVER ......

    Your problem is that your DIM statement for the iInput value is INSIDE the keydown event (therefore resetting the value to ZERO each time a key is pressed)

    something like the following may come close to what you want (VB6 code used)


    Private iInput As Integer

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

    If KeyCode = 84 Then 'T UpKey
    If iInput = 9 Then
    iInput = 0 'Reset when at 9
    Label2.Caption = iInput
    ElseIf iInput < 9 Then
    iInput = iInput + 1
    Label2.Caption = iInput

    End If
    ElseIf KeyCode = 68 Then 'D DownKey
    If iInput = 0 Then 'Do Not allow any more DownKey presses
    Label2.Caption = iInput
    ElseIf iInput >= 1 Then
    iInput = iInput - 1
    Label2.Caption = iInput

    End If
    End If
    End Sub

  3. #3
    Join Date
    Sep 2003
    Posts
    30
    hi
    thanks for the reply..
    but i still cant figure out wats wrong..
    when i press the T button the number only increases to 1 and not until 9.
    any idea?
    pls help
    i'm using visual studio.net 2002

  4. #4
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,900
    As I said

    Your problem is that your DIM statement for the iInput value is INSIDE the keydown event (therefore resetting the value to ZERO each time a key is pressed)

    So if you add 1 to Zero each time, you will always only get a result of 1

    Define your iInput value OUTSIDE the key_down event eg, in a module or above the event (Right up at the top of the form code)

    ie, OUTSIDE the key_down event

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

Featured