PDA

Click to See Complete Forum and Search --> : I'm having a problem.


netSurfer
Jan 25th, 2000, 03:31 AM
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.

Aaron Young
Jan 25th, 2000, 03:58 AM
You could figure out which Direction the User Pressed, by storing relative values and comparing them in the RowColChange Event, ie.

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
aarony@redwingsoftware.com
ajyoung@pressenter.com

netSurfer
Jan 25th, 2000, 08:22 PM
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.

Aaron Young
Jan 25th, 2000, 09:36 PM
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
aarony@redwingsoftware.com
ajyoung@pressenter.com

netSurfer
Jan 25th, 2000, 10:46 PM
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.

LG
Jan 25th, 2000, 10:53 PM
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

LG
Jan 26th, 2000, 12:15 AM
Thank you, Aaron. My fault, I was using mouse instead of arrow keys. Probably still sleepy.

Larisa

Aaron Young
Jan 26th, 2000, 11:10 AM
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
aarony@redwingsoftware.com
ajyoung@pressenter.com