• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 648
  • Last Modified:

SSTab Key Events fired twice Bug (VB6). Workaround? Fix?

I have an SSTab control with 4 tabs. I need the user to be able to cycle through the tabs using the keystroke: alt-f ...(crtl-tab works by default, but I also need alt-f). ...

THE PROBLEM is that there's apparently a bug (see KB article: 149273) in the SSTab control whereby key events get fired twice. I'm noticing this behavior: if I click a tab and then use alt-f to switch between them, it skips a tab... Interestingly, the alt-f behavior is fine *until* I click a tab with the mouse, after which point the key event gets fired twice every time I hit alt-f...

I'm looking for a workaround, or a fix of some sort... The Knowledgebase article suggests using a global to ignore the 2nd keyevent if focus is on the sstab, but this will not work for me as I need alt-f to work regardless of what control has focus (ie, the sstab may already have focus anyway)...

Here's the code I'm using (keyPreview = true is set in form load...), and the Microsoft Knowledgebase article describing the aforementioned bug in sstab:

http://support.microsoft.com/kb/149273/EN-US/

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = vbAltMask Then
        Select Case KeyCode
            Case vbKeyF: Call moveToNextTab
        End Select
    End If
End Sub

Private Sub moveToNextTab
    If SSTab1.Tab >= 3 Then
        SSTab1.Tab = 0
    Else
        SSTab1.Tab = SSTab1.Tab + 1
    End If
End Sub
0
Melvinivitch
Asked:
Melvinivitch
1 Solution
 
gary_jCommented:
For me, it never works, whether I've clicked on the SSTab or not -- it always jumps two
I think what is happeneing is that your moveToNextTab is causing a sstab click event

I solved it by setting a global variable:

Option Explicit
Dim g_bolClicked As Boolean

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = vbAltMask Then
        Select Case KeyCode
            Case vbKeyG: Call moveToNextTab
        End Select
    End If
End Sub

Private Sub moveToNextTab()
    If g_bolClicked = False Then
        g_bolClicked = True
        If SSTab1.Tab >= 3 Then
            SSTab1.Tab = 0
        Else
            SSTab1.Tab = SSTab1.Tab + 1
        End If
    Else
        g_bolClicked = False
    End If
End Sub
0
 
rettiseertCommented:
Add a KeyCode = 0 at the end of your Form_KeyDown event:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = vbAltMask Then
        Select Case KeyCode
            Case vbKeyF: Call moveToNextTab
        End Select
    End If
    KeyCode = 0
End Sub
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now