1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir 4*cdf0e10cSrcweir<!--*********************************************************************** 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * This file is part of OpenOffice.org. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 15*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 16*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 17*cdf0e10cSrcweir * 18*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 19*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 20*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 22*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 23*cdf0e10cSrcweir * 24*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 25*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 26*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 27*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 28*cdf0e10cSrcweir * 29*cdf0e10cSrcweir ************************************************************************--> 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir<helpdocument version="1.0"> 32*cdf0e10cSrcweir<meta> 33*cdf0e10cSrcweir<topic id="textsbasicguidesample_codexml" indexer="include" status="PUBLISH"> 34*cdf0e10cSrcweir<title id="tit" xml-lang="en-US">Programming Examples for Controls in the Dialog Editor</title> 35*cdf0e10cSrcweir<filename>/text/sbasic/guide/sample_code.xhp</filename> 36*cdf0e10cSrcweir</topic> 37*cdf0e10cSrcweir<history> 38*cdf0e10cSrcweir<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created> 39*cdf0e10cSrcweir<lastedited date="2005-01-12T10:40:14">converted from old format - fpe</lastedited> 40*cdf0e10cSrcweir</history> 41*cdf0e10cSrcweir</meta> 42*cdf0e10cSrcweir<body> 43*cdf0e10cSrcweir<bookmark xml-lang="en-US" branch="index" id="bm_id3155338"><bookmark_value>programming examples for controls</bookmark_value> 44*cdf0e10cSrcweir<bookmark_value>dialogs;loading (example)</bookmark_value> 45*cdf0e10cSrcweir<bookmark_value>dialogs;displaying (example)</bookmark_value> 46*cdf0e10cSrcweir<bookmark_value>controls;reading or editing properties (example)</bookmark_value> 47*cdf0e10cSrcweir<bookmark_value>list boxes;removing entries from (example)</bookmark_value> 48*cdf0e10cSrcweir<bookmark_value>list boxes;adding entries to (example)</bookmark_value> 49*cdf0e10cSrcweir<bookmark_value>examples; programming controls</bookmark_value> 50*cdf0e10cSrcweir<bookmark_value>dialog editor;programming examples for controls</bookmark_value> 51*cdf0e10cSrcweir</bookmark> 52*cdf0e10cSrcweir<paragraph role="heading" id="hd_id3155338" xml-lang="en-US" level="1" l10n="U" oldref="1"><variable id="sample_code"><link href="text/sbasic/guide/sample_code.xhp" name="Programming Examples for Controls in the Dialog Editor">Programming Examples for Controls in the Dialog Editor</link> 53*cdf0e10cSrcweir</variable></paragraph> 54*cdf0e10cSrcweir<paragraph role="paragraph" id="par_id3153031" xml-lang="en-US" l10n="CHG" oldref="2">The following examples are for a new <link href="text/sbasic/guide/create_dialog.xhp" name="dialog">dialog</link> called "Dialog1". Use the tools on the <emph>Toolbox</emph> bar in the dialog editor to create the dialog and add the following controls: a <emph>Check Box</emph> called "CheckBox1", a <emph>Label Field</emph> called "Label1", a <emph>Button</emph> called "CommandButton1", and a <emph>List Box</emph> called "ListBox1".</paragraph> 55*cdf0e10cSrcweir<paragraph role="warning" id="par_id3154141" xml-lang="en-US" l10n="U" oldref="3">Be consistent with uppercase and lowercase letter when you attach a control to an object variable.</paragraph> 56*cdf0e10cSrcweir<paragraph role="heading" id="hd_id3154909" xml-lang="en-US" level="3" l10n="U" oldref="4">Global Function for Loading Dialogs</paragraph> 57*cdf0e10cSrcweir<paragraph role="code" id="par_id3153193" xml-lang="en-US" l10n="U" oldref="73">Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)</paragraph> 58*cdf0e10cSrcweir<paragraph role="code" id="par_id3145787" xml-lang="en-US" l10n="U" oldref="74">Dim oLib as Object</paragraph> 59*cdf0e10cSrcweir<paragraph role="code" id="par_id3148576" xml-lang="en-US" l10n="U" oldref="75">Dim oLibDialog as Object</paragraph> 60*cdf0e10cSrcweir<paragraph role="code" id="par_id3153726" xml-lang="en-US" l10n="U" oldref="76">Dim oRuntimeDialog as Object</paragraph> 61*cdf0e10cSrcweir<paragraph role="code" id="par_id3149261" xml-lang="en-US" l10n="U" oldref="77">If IsMissing(oLibContainer ) then</paragraph> 62*cdf0e10cSrcweir<paragraph role="code" id="par_id3148646" xml-lang="en-US" l10n="U" oldref="78">oLibContainer = DialogLibraries</paragraph> 63*cdf0e10cSrcweir<paragraph role="code" id="par_id3151115" xml-lang="en-US" l10n="U" oldref="79">End If</paragraph> 64*cdf0e10cSrcweir<paragraph role="code" id="par_id3146986" xml-lang="en-US" l10n="U" oldref="80">oLibContainer.LoadLibrary(LibName)</paragraph> 65*cdf0e10cSrcweir<paragraph role="code" id="par_id3145366" xml-lang="en-US" l10n="U" oldref="81">oLib = oLibContainer.GetByName(Libname)</paragraph> 66*cdf0e10cSrcweir<paragraph role="code" id="par_id3145271" xml-lang="en-US" l10n="U" oldref="82">oLibDialog = oLib.GetByName(DialogName)</paragraph> 67*cdf0e10cSrcweir<paragraph role="code" id="par_id3144764" xml-lang="en-US" l10n="U" oldref="83">oRuntimeDialog = CreateUnoDialog(oLibDialog)</paragraph> 68*cdf0e10cSrcweir<paragraph role="code" id="par_id3153876" xml-lang="en-US" l10n="U" oldref="84">LoadDialog() = oRuntimeDialog</paragraph> 69*cdf0e10cSrcweir<paragraph role="code" id="par_id3156286" xml-lang="en-US" l10n="U" oldref="85">End Function</paragraph> 70*cdf0e10cSrcweir<paragraph role="heading" id="hd_id3149412" xml-lang="en-US" level="3" l10n="U" oldref="18">Displaying a Dialog</paragraph> 71*cdf0e10cSrcweir<paragraph role="code" id="par_id3145801" xml-lang="en-US" l10n="U" oldref="86">rem global definition of variables</paragraph> 72*cdf0e10cSrcweir<paragraph role="code" id="par_id3150716" xml-lang="en-US" l10n="U" oldref="87">Dim oDialog1 AS Object</paragraph> 73*cdf0e10cSrcweir<paragraph role="code" id="par_id3154510" xml-lang="en-US" l10n="U" oldref="88">Sub StartDialog1</paragraph> 74*cdf0e10cSrcweir<paragraph role="code" id="par_id3146913" xml-lang="en-US" l10n="U" oldref="162">BasicLibraries.LoadLibrary("Tools")</paragraph> 75*cdf0e10cSrcweir<paragraph role="code" id="par_id3150327" xml-lang="en-US" l10n="U" oldref="89">oDialog1 = LoadDialog("Standard", "Dialog1")</paragraph> 76*cdf0e10cSrcweir<paragraph role="code" id="par_id3155767" xml-lang="en-US" l10n="U" oldref="92">oDialog1.Execute()</paragraph> 77*cdf0e10cSrcweir<paragraph role="code" id="par_id3149019" xml-lang="en-US" l10n="U" oldref="93">end sub</paragraph> 78*cdf0e10cSrcweir<paragraph role="heading" id="hd_id3150042" xml-lang="en-US" level="3" l10n="U" oldref="27">Read or Edit Properties of Controls in the Program</paragraph> 79*cdf0e10cSrcweir<paragraph role="code" id="par_id3159267" xml-lang="en-US" l10n="U" oldref="136">Sub Sample1</paragraph> 80*cdf0e10cSrcweir<paragraph role="code" id="par_id3155335" xml-lang="en-US" l10n="U" oldref="163">BasicLibraries.LoadLibrary("Tools")</paragraph> 81*cdf0e10cSrcweir<paragraph role="code" id="par_id3163808" xml-lang="en-US" l10n="U" oldref="137">oDialog1 = LoadDialog("Standard", "Dialog1")</paragraph> 82*cdf0e10cSrcweir<paragraph role="code" id="par_id3145232" xml-lang="en-US" l10n="U" oldref="138">REM get dialog model</paragraph> 83*cdf0e10cSrcweir<paragraph role="code" id="par_id3146316" xml-lang="en-US" l10n="U" oldref="139">oDialog1Model = oDialog1.Model</paragraph> 84*cdf0e10cSrcweir<paragraph role="code" id="par_id3154021" xml-lang="en-US" l10n="U" oldref="140">REM display text of Label1</paragraph> 85*cdf0e10cSrcweir<paragraph role="code" id="par_id3150301" xml-lang="en-US" l10n="U" oldref="141">oLabel1 = oDialog1.GetControl("Label1")</paragraph> 86*cdf0e10cSrcweir<paragraph role="code" id="par_id3152584" xml-lang="en-US" l10n="U" oldref="142">MsgBox oLabel1.Text</paragraph> 87*cdf0e10cSrcweir<paragraph role="code" id="par_id3151277" xml-lang="en-US" l10n="U" oldref="143">REM set new text for control Label1</paragraph> 88*cdf0e10cSrcweir<paragraph role="code" id="par_id3154119" xml-lang="en-US" l10n="U" oldref="144">oLabel1.Text = "New Files"</paragraph> 89*cdf0e10cSrcweir<paragraph role="code" id="par_id3155115" xml-lang="en-US" l10n="U" oldref="145">REM display model properties for the control CheckBox1</paragraph> 90*cdf0e10cSrcweir<paragraph role="code" id="par_id3166426" xml-lang="en-US" l10n="U" oldref="146">oCheckBox1Model = oDialog1Model.CheckBox1</paragraph> 91*cdf0e10cSrcweir<paragraph role="code" id="par_id3153270" xml-lang="en-US" l10n="U" oldref="147">MsgBox oCheckBox1Model.Dbg_Properties</paragraph> 92*cdf0e10cSrcweir<paragraph role="code" id="par_id3149817" xml-lang="en-US" l10n="U" oldref="148">REM set new state for CheckBox1 for model of control</paragraph> 93*cdf0e10cSrcweir<paragraph role="code" id="par_id3145134" xml-lang="en-US" l10n="U" oldref="149">oCheckBox1Model.State = 1</paragraph> 94*cdf0e10cSrcweir<paragraph role="code" id="par_id3159102" xml-lang="en-US" l10n="U" oldref="150">REM display model properties for control CommandButton1</paragraph> 95*cdf0e10cSrcweir<paragraph role="code" id="par_id3152777" xml-lang="en-US" l10n="U" oldref="151">oCMD1Model = oDialog1Model.CommandButton1</paragraph> 96*cdf0e10cSrcweir<paragraph role="code" id="par_id3149209" xml-lang="en-US" l10n="U" oldref="152">MsgBox oCMD1Model.Dbg_Properties</paragraph> 97*cdf0e10cSrcweir<paragraph role="code" id="par_id3150368" xml-lang="en-US" l10n="U" oldref="153">REM display properties of control CommandButton1</paragraph> 98*cdf0e10cSrcweir<paragraph role="code" id="par_id3150883" xml-lang="en-US" l10n="U" oldref="154">oCMD1 = oDialog1.GetControl("CommandButton1")</paragraph> 99*cdf0e10cSrcweir<paragraph role="code" id="par_id3155380" xml-lang="en-US" l10n="U" oldref="155">MsgBox oCMD1.Dbg_Properties</paragraph> 100*cdf0e10cSrcweir<paragraph role="code" id="par_id3150201" xml-lang="en-US" l10n="U" oldref="156">REM execute dialog</paragraph> 101*cdf0e10cSrcweir<paragraph role="code" id="par_id3154485" xml-lang="en-US" l10n="U" oldref="157">oDialog1.Execute()</paragraph> 102*cdf0e10cSrcweir<paragraph role="code" id="par_id3146115" xml-lang="en-US" l10n="U" oldref="158">End Sub</paragraph> 103*cdf0e10cSrcweir<paragraph role="heading" id="hd_id3145387" xml-lang="en-US" level="3" l10n="U" oldref="55">Add an Entry to a ListBox</paragraph> 104*cdf0e10cSrcweir<paragraph role="code" id="par_id3155088" xml-lang="en-US" l10n="U" oldref="122">Sub AddEntry</paragraph> 105*cdf0e10cSrcweir<paragraph role="code" id="par_id3154528" xml-lang="en-US" l10n="U" oldref="164">BasicLibraries.LoadLibrary("Tools")</paragraph> 106*cdf0e10cSrcweir<paragraph role="code" id="par_id3159222" xml-lang="en-US" l10n="U" oldref="159">oDialog1 = LoadDialog("Standard", "Dialog1")</paragraph> 107*cdf0e10cSrcweir<paragraph role="code" id="par_id3148700" xml-lang="en-US" l10n="U" oldref="123">REM adds a new entry to the ListBox</paragraph> 108*cdf0e10cSrcweir<paragraph role="code" id="par_id3159173" xml-lang="en-US" l10n="U" oldref="124">oDialog1Model = oDialog1.Model</paragraph> 109*cdf0e10cSrcweir<paragraph role="code" id="par_id3153305" xml-lang="en-US" l10n="U" oldref="125">oListBox = oDialog1.GetControl("ListBox1")</paragraph> 110*cdf0e10cSrcweir<paragraph role="code" id="par_id3153914" xml-lang="en-US" l10n="U" oldref="126">dim iCount as integer</paragraph> 111*cdf0e10cSrcweir<paragraph role="code" id="par_id3151243" xml-lang="en-US" l10n="U" oldref="127">iCount = oListbox.ItemCount</paragraph> 112*cdf0e10cSrcweir<paragraph role="code" id="par_id3144504" xml-lang="en-US" l10n="U" oldref="128">oListbox.additem("New Item" & iCount,0)</paragraph> 113*cdf0e10cSrcweir<paragraph role="code" id="par_id3149328" xml-lang="en-US" l10n="U" oldref="129">end sub</paragraph> 114*cdf0e10cSrcweir<paragraph role="heading" id="hd_id3147071" xml-lang="en-US" level="3" l10n="U" oldref="64">Remove an Entry from a ListBox</paragraph> 115*cdf0e10cSrcweir<paragraph role="code" id="par_id3159095" xml-lang="en-US" l10n="U" oldref="130">Sub RemoveEntry</paragraph> 116*cdf0e10cSrcweir<paragraph role="code" id="par_id3154958" xml-lang="en-US" l10n="U" oldref="165">BasicLibraries.LoadLibrary("Tools")</paragraph> 117*cdf0e10cSrcweir<paragraph role="code" id="par_id3149443" xml-lang="en-US" l10n="U" oldref="160">oDialog1 = LoadDialog("Standard", "Dialog1")</paragraph> 118*cdf0e10cSrcweir<paragraph role="code" id="par_id3153247" xml-lang="en-US" l10n="U" oldref="131">REM remove the first entry from the ListBox</paragraph> 119*cdf0e10cSrcweir<paragraph role="code" id="par_id3151302" xml-lang="en-US" l10n="U" oldref="132">oDialog1Model = oDialog1.Model</paragraph> 120*cdf0e10cSrcweir<paragraph role="code" id="par_id3153976" xml-lang="en-US" l10n="U" oldref="133">oListBox = oDialog1.GetControl("ListBox1")</paragraph> 121*cdf0e10cSrcweir<paragraph role="code" id="par_id3155383" xml-lang="en-US" l10n="U" oldref="134">oListbox.removeitems(0,1)</paragraph> 122*cdf0e10cSrcweir<paragraph role="code" id="par_id3150892" xml-lang="en-US" l10n="U" oldref="135">end sub</paragraph> 123*cdf0e10cSrcweir<section id="relatedtopics"> 124*cdf0e10cSrcweir<embed href="text/sbasic/guide/control_properties.xhp#control_properties"/> 125*cdf0e10cSrcweir<embed href="text/sbasic/guide/create_dialog.xhp#create_dialog"/> 126*cdf0e10cSrcweir<embed href="text/sbasic/guide/insert_control.xhp#insert_control"/> 127*cdf0e10cSrcweir<embed href="text/sbasic/guide/show_dialog.xhp#show_dialog"/> 128*cdf0e10cSrcweir</section> 129*cdf0e10cSrcweir</body> 130*cdf0e10cSrcweir</helpdocument> 131