Programming Examples for Controls in the Dialog Editor/text/sbasic/guide/sample_code.xhpSun Microsystems, Inc.converted from old format - fpeprogramming examples for controlsdialogs;loading (example)dialogs;displaying (example)controls;reading or editing properties (example)list boxes;removing entries from (example)list boxes;adding entries to (example)examples; programming controlsdialog editor;programming examples for controlsProgramming Examples for Controls in the Dialog Editor
The following examples are for a new dialog called "Dialog1". Use the tools on the Toolbox bar in the dialog editor to create the dialog and add the following controls: a Check Box called "CheckBox1", a Label Field called "Label1", a Button called "CommandButton1", and a List Box called "ListBox1".Be consistent with uppercase and lowercase letter when you attach a control to an object variable.Global Function for Loading DialogsFunction LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)Dim oLib as ObjectDim oLibDialog as ObjectDim oRuntimeDialog as ObjectIf IsMissing(oLibContainer ) thenoLibContainer = DialogLibrariesEnd IfoLibContainer.LoadLibrary(LibName)oLib = oLibContainer.GetByName(Libname)oLibDialog = oLib.GetByName(DialogName)oRuntimeDialog = CreateUnoDialog(oLibDialog)LoadDialog() = oRuntimeDialogEnd FunctionDisplaying a Dialogrem global definition of variablesDim oDialog1 AS ObjectSub StartDialog1BasicLibraries.LoadLibrary("Tools")oDialog1 = LoadDialog("Standard", "Dialog1")oDialog1.Execute()end subRead or Edit Properties of Controls in the ProgramSub Sample1BasicLibraries.LoadLibrary("Tools")oDialog1 = LoadDialog("Standard", "Dialog1")REM get dialog modeloDialog1Model = oDialog1.ModelREM display text of Label1oLabel1 = oDialog1.GetControl("Label1")MsgBox oLabel1.TextREM set new text for control Label1oLabel1.Text = "New Files"REM display model properties for the control CheckBox1oCheckBox1Model = oDialog1Model.CheckBox1MsgBox oCheckBox1Model.Dbg_PropertiesREM set new state for CheckBox1 for model of controloCheckBox1Model.State = 1REM display model properties for control CommandButton1oCMD1Model = oDialog1Model.CommandButton1MsgBox oCMD1Model.Dbg_PropertiesREM display properties of control CommandButton1oCMD1 = oDialog1.GetControl("CommandButton1")MsgBox oCMD1.Dbg_PropertiesREM execute dialogoDialog1.Execute()End SubAdd an Entry to a ListBoxSub AddEntryBasicLibraries.LoadLibrary("Tools")oDialog1 = LoadDialog("Standard", "Dialog1")REM adds a new entry to the ListBoxoDialog1Model = oDialog1.ModeloListBox = oDialog1.GetControl("ListBox1")dim iCount as integeriCount = oListbox.ItemCountoListbox.additem("New Item" & iCount,0)end subRemove an Entry from a ListBoxSub RemoveEntryBasicLibraries.LoadLibrary("Tools")oDialog1 = LoadDialog("Standard", "Dialog1")REM remove the first entry from the ListBoxoDialog1Model = oDialog1.ModeloListBox = oDialog1.GetControl("ListBox1")oListbox.removeitems(0,1)end sub