Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 19th, 2004, 10:33 AM
Registered User
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scrolling thru a large list box - using keystrokes

My application is asp vbscript based. I have a number of list boxes with 100's of entries. If the user makes the list box active, they can hit a single key and they will be place into that portion of the list. Is there any way to make the list box to scroll based on two or three keystokes - like address box in outlook.



Reply With Quote
  #2 (permalink)  
Old August 27th, 2004, 07:20 AM
Registered User
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

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
        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
        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
        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
                frm.<name>.selectedIndex = x
            End If
            exit for
        End If

end sub

Not all that pretty but it works.


Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
Large report in text box takabyte Beginning VB 6 3 August 6th, 2007 07:32 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
Scrolling on text box echovue Access VBA 2 January 3rd, 2007 03:57 PM
scrolling text box bezaman Classic ASP Basics 6 November 10th, 2005 05:26 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.