Liberty BASIC Help Online

Combobox
Image comboclose.GIF    
 
Image comboopen.GIF
 
COMBOBOX #handle.ext, array$(), eventHandler, xPos, yPos, wide, high
 
Description:
Comboboxes are a lot like listboxes, but they are designed to save space.  Instead of showing an entire list of items, they show only the selected one.  When the user clicks on the checkbox arrow button (to the right), a list appears (drops down).  It is then possible to browse the possible selections, and pick one if so desired.  When the selection is made, the new selection is highlighted.  The user can type into the textbox part on top of the combobox, rather than choosing an item from the dropdown list.  The program can get the contents of this field. The combobox is loaded with a collection of strings from a specified string array, and a reload command updates the contents of the combobox from the array when the contents of array change.
 
#handle.ext
The #handle part of this item needs to be the same as the handle of the window containing the combobox.  The .extpart needs to be unique so that the program can send commands to the combobox 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 combobox.  Be sure to load the array with strings before opening the window.  If some time later it becomes necessary to change the contents of the combobox, simply change the contents of the array and send a RELOAD command to the combobox. 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 combobox by clicking it.  See also:  Controls and Events
xPos & yPos 
These coordinates specify the the distance in x and y (in pixels) of the combobox from the upper-left corner of the window.
 
wide & high 
These parameters determine the width and height  (in pixels) of the combobox.  "Height" in this case refers to the length of the selection list when the combobox's button is clicked, not to the size of the initial selection window, which is dependant upon the size of the font.
 
Here are the commands for combobox:
 
print #handle.ext, "!contents"
This command sets the contents of the field part of the combobox to the string after the !.
 
print #handle.ext, "contents? text$"
This retrieves the contents of the text field of the combobox into the variable called text$.
 
print #handle.ext, "locate x y width height"
This respositions the combobox in its window.  This is effective when the combobox is placed inside window of type "window" or "dialog".  The combobox 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 control'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, "select string"
This selects the item the same as "string" and updates the display.  Note that "string" must be a valid item from the combobox 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, "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 combobox 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 places the selected string into the variable 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 places the index of the selected string into the variable called index.  If there is no selected item, then index will be set to 0.
 
print #handle.ext, "reload"
This reloads the combobox with the current contents of its array and updates the display.
 
print #handle.ext, "setfocus"
This causes the combobox to receive the input focus.  This means that any keypresses are directed to the combobox.
 
print #handle,ext, "locate x y width height"
This repositions the combobox 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 RESIZER.BAS example program.
 
print #handle.ext, "font facename pointSize"
This sets the combox'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, "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.
 
Usage:
 
'combobox demo with branch label event handler
 
nomainwin
a$(1) = "one"
a$(2) = "two"
a$(3) = "three"
a$(4) = "four"
 
combobox #win.combo, a$(),[doCombo],10,10,120,200
open "Combobox Demo" for window as #win
#win "trapclose [Quit]"
#win.combo "selectindex 1"
 
wait
 
[Quit] close #win:end
 
[doCombo]
#win.combo "selection? sel$"
notice "You chose ";sel$
wait
 
'combobox demo with subroutine event handler
nomainwin
a$(1) = "one"
a$(2) = "two"
a$(3) = "three"
a$(4) = "four"
 
combobox #win.combo, a$(),doCombo,10,10,120,200
 
open "Combobox Demo" for window as #win
#win "trapclose Quit"
#win.combo "selectindex 1"
 
wait
 
sub Quit handle$
close #handle$
end
end sub
 
sub doCombo handle$
#handle$ "selection? sel$"
notice "You chose ";sel$
end sub
 
 
 
 
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/