View Single Post
  #2 (permalink)  
Old August 27th, 2004, 07:20 AM
bill unswort bill unswort is offline
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had trouble getting window.event.shiftkey and window.event.altkey to work. I had to go key code by key on my key board.

All of the following code must be Inside the CLIENT SCRIPT AREA

The following dim's must be global inside the client script

dim strHoldAllKeyStrokes
dim strHoldSingleKeyStroke
dim x

The following function needs to appear just once in the client area

Function fncBufferKeyStrokes

    rem shift key or control key
    If window.event.keycode = 16 Or _
       window.event.keycode = 17 Then
        fncBufferKeyStrokes = "<SPECIAL>"
        Exit Function
    End If

    rem Get the key that was just pressed
    strHoldSingleKeyStroke = Chr(window.event.keycode)

    rem The dash key on my keyboard has an ascii code of 189 which is "1/2" sysmbol ???
    If Asc(strHoldSingleKeyStroke) = 189 Then
        strHoldSingleKeyStroke = "-"
    End If

    rem If a key pressed is not one I can handle make it empty
    If (strHoldSingleKeyStroke => "0" And _
        strHoldSingleKeyStroke =< "9") Or _
       (strHoldSingleKeyStroke => "a" And _
        strHoldSingleKeyStroke =< "z") Or _
       (strHoldSingleKeyStroke => "A" And _
        strHoldSingleKeyStroke =< "Z") Or _
       strHoldSingleKeyStroke = " " Or _
       strHoldSingleKeyStroke = "." Or _
       strHoldSingleKeyStroke = "," Or _
        strHoldSingleKeyStroke = "-" Or _
       Asc(strHoldSingleKeyStroke) = 46 Then
        rem Key Stroke is acceptable
    Else
        strHoldSingleKeyStroke = ""
    End If

    rem If delete key remove previous key stroke
    If strHoldSingleKeyStroke = "" Then
        rem If the key stroke was not acceptable the ASC function will error
    Else
        If Asc(strHoldSingleKeyStroke) = 46 Then
            If Len(strHoldAllKeyStrokes) > 0 Then
                strHoldAllKeyStrokes = Mid(strHoldAllKeyStrokes, 1, Len(strHoldAllKeyStrokes) - 1)
            End If
        End If
    End If

    rem Build up the saved keystrokes
    If Asc(strHoldSingleKeyStroke) = 46 Then
        rem do not add on the delete key
    Else
        strHoldAllKeyStrokes = strHoldAllKeyStrokes & strHoldSingleKeyStroke
    End If

    fncBufferKeyStrokes = strHoldAllKeyStrokes

end Function

Each List box needs two routines. Change <Name> to the name of your list box

sub <name>_onClick
    rem clear out the stored keystrokes when the user first clickes into the combo box
    strHoldAllKeyStrokes = ""
end sub
sub <name>_onkeyUp

    On Error Resume Next

    strHoldAllKeyStrokes = fncBufferKeyStrokes

    If Instr(strHoldAllKeyStrokes, "<SPECIAL>") > 0 Then
           Exit Sub
    End If

    rem Search thru list and set the index in the list. Combo boxes in IE do not have a total count
    rem of total entries. When we get an error - gone past end of list box set the index to the last entry
    For x = 0 to 4000
        If strHoldAllKeyStrokes =< Mid(frm.<name>.item(x).text, 1, len(strHoldAllKeyStrokes)) Then
            If err.number = 424 Then
                frm.<name>.selectedIndex = x - 1
            Else
                frm.<name>.selectedIndex = x
            End If
            exit for
        End If
    next

end sub

Not all that pretty but it works.

bill




Reply With Quote