Results 1 to 8 of 8

Thread: I'm having a problem.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Using MSflexgrid, I need to capture when the user presses the arrows. I put some code in to capture them in the KeyDown event but it only seems to be equal to an arrow if I'm holidng CTRL down at the same time.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    You could figure out which Direction the User Pressed, by storing relative values and comparing them in the RowColChange Event, ie.
    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub MSFlexGrid1_RowColChange()
        Static lRow As Long
        Static lCol As Long
        
        With MSFlexGrid1
            If GetAsyncKeyState(vbLeftButton) = 0 Then
                If lCol <> .Col Then
                    Caption = IIf(lCol > .Col, "Left", "Right")
                    lCol = .Col
                Else
                    If lRow <> .Row Then
                        Caption = IIf(lRow > .Row, "Up", "Down")
                        lRow = .Row
                    End If
                End If
            Else
                Caption = ""
                lRow = .Row
                lCol = .Col
            End If
        End With
    End Sub
    I use the GetAsyncKeyState API to determine when the User is Navigating with the Mouse, not the Keys.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    ok, I have a couple questions about the code you posted. I dokn't think I've ever seen the Static statement used like that. I think I know what it does but could you explain?

    I didn't know that you could just add a Sub to a control like that. Is this a special case or can you do that with other controls?

    Also:

    Caption = IIf(....)

    what does the IIf do? I've never seen it before.


  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Declaring a Variable as Static Means that the Value is Stored when the Sub/Function Exits and Restored when Next Run, so any Changes you make to the Variable will be there next time.

    I didn't add the Sub to the Control, RowColChange() is a Native Sub of the MSFlexGrid Control.

    The Immeadiate If, (IIF), Returns 1 of 2 Values Depending on Whether the Expression is True or False, you should note that regardless of the Value returned, Both are Evaluated.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Thanks Aaron, that made things alot clearer. The reason I asked about adding the sub is because it wasn't listed there until I pasted the code. Once I pasted it, I didn't actually need any of the other code.

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Hi, Aaron.
    Is your code should change the caption? But MSFlexgrid doesn't have a caption property.
    I cannot get it work. I have tried to pass values to text box and it doesn't show anything. What I am doing wrong?

    Larisa

  7. #7
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Thank you, Aaron. My fault, I was using mouse instead of arrow keys. Probably still sleepy.

    Larisa

  8. #8
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Larisa,

    I'm not Referencing the MSFlexGrid when I use the Caption Property, so it's actually Changing the Forms Caption.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


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