Liberty BASIC Help Online

Listbox
Image listbox.GIF
 
LISTBOX #handle.ext, array$(), eventHandler, x, y, wide, high
 
Description:
Listboxes are added to windows to provide a list selection capability in programs.  The listbox is loaded with a collection of strings from a specified string array, and a RELOAD command updates the contents of the listbox from the array when the contents of the array change.
 
 
#handle.ext 
The #handle part of this statement must be the same as the #handle of the window that contains the listbox.  The ".ext" part must be unique so that the program can send commands to the listbox and get information from it later.
 
array$() 
This is the name of the array (must be a string array) that contains the contents of the listbox.  Be sure to load the array with strings before opening the window.  If some time later it is necessary to change the contents of the listbox, simply change the contents of the array and send a RELOAD command. The index numbers  of items in the array may not match the index numbers of the same items in the control. The control is loaded from the array, and the first index used in the control is "1". No empty strings are loaded into the control, so only array items that contain text are loaded.
 
eventHandler
This is the branch label or subroutine where execution begins when the user selects an item from the listbox by double-clicking.  Selection by only single clicking does not cause branching to occur unless a "singleclickselect" command is issued to the listbox.  See also:  Controls and Events
 
x, y
This is the distance in x and y (in pixels) of the listbox from the upper-left corner of the window.
 
wide, high 
This specifies the width and height (in pixels) of the listbox.
 
Here are the commands for listbox:
 
print #handle.ext, "select string"
This selects the item the same as "string" and updates the display.  If a variable is to be used in this command, it must be located outside the quotation marks, with the blank space preserved:
 
print #handle.ext, "select "; string$
 
 
print #handle.ext, "selectindex i"
This selects the item at index position i and updates the display.  Note that "i" must be a valid index number for the listbox array.  If a variable is to be used in this command, it must be located outside the quotation marks, with the blank space preserved:
print #handle.ext, "selectindex "; i
 
print #handle.ext, "selection? selected$"
This will place the string of the item currently selected into selected$.  If there is no selected item, then selected$ will be a string of zero length (a null string).
 
print #handle.ext, "selectionindex? index"
This will place the index of the currently selected string into index.  If there is no selected item, then index will be set to 0.
 
print #handle.ext, "reload"
This will reload the listbox with the current contents of its array and will update the display.
 
print #handle.ext, "locate x y width height"
This repositions the listbox control in its window.  This only works if the control is placed inside window of type "window".  The control will not update its size and location until a REFRESH command is sent to the window.  See the RESIZE.BAS example program.
 
print #handle.ext, "font facename pointSize"
This sets the listbox's font to the specified face and point size.  If an exact match cannot be found, then Liberty BASIC will try to find a close match, with size taking precedence over face.  For more on specifying fonts read How to Specify Fonts
 
Example:
print #handle.ext, "font times_new_roman 10"
 
print #handle.ext, "singleclickselect"
This tells Liberty BASIC to jump to the control's branch label on a single click, instead of the default double click.
 
print #handle.ext, "setfocus"
This causes the control to receive the input focus. This means that any keypresses will be directed to the control.
 
print #handle.ext, "enable"
This causes the control to be enabled.
 
 
print #handle.ext, "disable"
This causes the control to be inactive and grayed-out.
 
 
print #handle.ext, "show"
This causes the control to be visible.
 
 
print #handle.ext, "hide"
This causes the control to be hidden or invisible.
 
 
Sample Program
 
'Branch Label Event Handler
' Sample program.  Pick a contact status
options$(0) = "Cold Contact Phone Call"
options$(1) = "Send Literature"
options$(2) = "Follow Up Call"
options$(3) = "Send Promotional"
options$(4) = "Final Call"
 
listbox #status.list, options$(), [selectionMade], 5, 35, 250, 90
button #status, "Continue", [selectionMade], UL, 5, 5
button #status, "Cancel", [cancelStatusSelection], UR, 15, 5
WindowWidth = 270 : WindowHeight = 180
open "Select a contact status" for window as #status
 
wait
 
[selectionMade]
print #status.list, "selection? selection$"
notice selection$ + " was chosen"
close #status
end
 
[cancelStatusSelection]
notice "Status selection cancelled"
close #status
end
 
Control of the listbox in the sample program above is provided by printing commands to the listbox, just as with general window types in Liberty BASIC.  The listbox has the handle #status.list, so to find out what was selected, use the statement print #status.list, "selection? selection$".  If the result is a string of length zero (a null string), this means that there is no item selected.
 
Subroutine Event Handler:
' Sample program.  Pick a contact status
options$(0) = "Cold Contact Phone Call"
options$(1) = "Send Literature"
options$(2) = "Follow Up Call"
options$(3) = "Send Promotional"
options$(4) = "Final Call"
 
listbox #status.list, options$(), selectionMade, 5, 35, 250, 90
button #status, "Cancel", [cancelStatusSelection], UR, 15, 5
WindowWidth = 270 : WindowHeight = 180
open "Select a contact status" for window as #status
#status.list "singleclickselect"
 
wait
 
sub selectionMade handle$
print #status.list, "selection? selection$"
notice selection$ + " was chosen with listbox ";handle$
end sub
 
[cancelStatusSelection]
notice "Status selection cancelled"
close #status
end
 
 
 
 
For information on creating controls with different background colors, see Colors and the Graphical User Interface.


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/