Dialog Support

 

Cypress Enable has support for custom dialogs.  The syntax is similar to the syntax used in Microsoft Word Basic. The dialog syntax is not part of Microsoft Visual Basic or Microsoft Visual Basic For Applications (VBA).   Enable has complete support for dialogs.  The type of dialogs supported are outlined below.

 

Dialog Box controls

 

Enable Basic supports the standard Windows dialog box controls.  This section introduces the controls available for custom dialog boxes and provides guidelines for using them.

 

The Dialog Box syntax begins with the statement “Begin Dialog”.  The first two parameters of this statement are optional.  If they are left off the dialog will automatically be centered.

 

Begin Dialog DialogName1 240, 184, "Test Dialog"

 

Begin Dialog DialogName1 60, 60,240, 184, "Test Dialog"

 

OK and Cancel Buttons

 

Sub Main

   Begin Dialog ButtonSample 16,32,180,96,"OK and Cancel"

   OKButton 132,8,40,14

   CancelButton 132,28,40,14

End Dialog

      Dim Dlg1 As ButtonSample

      Button = Dialog (Dlg1)

End Sub

 

 

        Every custom dialog box must contain at least one “command” button - a OK button or a Cancel button.  Enable includes separate dialog box definition statements for each of these two types of buttons. 

 

List Boxes, Combo Boxes and Drop-down List Boxes 

 

Sub Main

   Dim MyList$ (5)

   MyList (0) = "line Item 1"

   MyList (1) = "line Item 2"

   MyList (2) = "line Item 3"

   MyList (3) = "line Item 4"

   MyList (4) = "line Item 5"

   MyList (5) = "line Item 6"

 

Begin Dialog BoxSample 16,35,256,89,"List Box, Combo Box, and Drop-Down List Box"

   OKButton 204,24,40,14

   CancelButton 204,44,40,14

   ListBox 12,24,48,40, MyList$( ),.Lstbox

   DropListBox 124,24,72,40, MyList$( ),.DrpList

   ComboBox 68,24,48,40, MyList$( ),.CmboBox

   Text 12,12,32,8,"List Box:"

   Text 124,12,68,8,"Drop-Down List Box:"

   Text 68,12,44,8,"Combo Box:"

End Dialog

   Dim Dlg1 As BoxSample

   Button = Dialog ( Dlg1 )

 

End Sub

 

        You can use a list box, drop-down list box, or combo box to present a list of items from which the user can select.  A drop-down list box saves space (it can drop down to cover other dialog box controls temporarily).  A combo box allows the user either to select an item from the list or type in a new item.  The items displayed in a list box, drop-down list box, or combo box are stored in an array that is defined before the instructions that define the dialog box.

 

Check Boxes

 

 

   Sub Main

      Begin Dialog CheckSample15,32,149,96,"Check Boxes"

      OKButton 92,8,40,14

      CancelButton 92,32,40,14

      CheckBox 12,8,45,8,"CheckBox",.CheckBox1

      CheckBox 12,24,45,8,"CheckBox",.CheckBox2

      CheckBox 12,40,45,8,"CheckBox",.CheckBox3

      CheckBox 12,56,45,8,"CheckBox",.CheckBox4

   End Dialog

      Dim Dlg1 As CheckSample

      Button = Dialog ( Dlg1 )

   End Sub

 

         

 

You use a check box to make a “yes or no” or “on or off” choice.  for example, you could use a check box to display or hide a toolbar in your application.

 

Text Boxes and Text

 

 

   Sub Main

      Begin Dialog TextBoxSample 16,30,180,96,"Text Boxes and Text"

      OKButton 132,20,40,14

      CancelButton 132,44,40,14

      Text 8,8,32,8,"Text Box:"

      TextBox 8,20,100,12,.TextBox1

      Text 8,44,84,8,"Multiline Text Box:"

      TextBox 8,56,100,32,.TextBox2

   End Dialog

      Dim Dlg1 As TextBoxSample

      Button = Dialog ( Dlg1 )

 

   End Sub

 

a text box control is a box in which the user can enter text while the dialog box is displayed.  By default, a text box holds a single line of text. Enable support single and multi-line text boxes.  The last parameter of the textbox function contains a variable to set the textbox style.

 

'=========================================================

' This sample shows how to implement a multiline textbox

'=========================================================

Const ES_LEFT             = &h0000&  'Try these different styles or-ed together

Const ES_CENTER           = &h0001&  ' as the last parameter of Textbox the change

Const ES_RIGHT            = &h0002&  ' the text box style.

Const ES_MULTILINE        = &h0004&  ' A 1 in the last parameter position defaults to

Const ES_UPPERCASE        = &h0008&  ' A multiline, Wantreturn, AutoVScroll testbox.

Const ES_LOWERCASE        = &h0010&

Const ES_PASSWORD         = &h0020&

Const ES_AUTOVSCROLL      = &h0040&

Const ES_AUTOHSCROLL      = &h0080&

Const ES_NOHIDESEL        = &h0100&

Const ES_OEMCONVERT       = &h0400&

Const ES_READONLY         = &h0800&

Const ES_WANTRETURN       = &h1000&

Const ES_NUMBER           = &h2000&

 

Sub Multiline

    Begin Dialog DialogType 60, 60, 140, 185, "Multiline text Dialog", .DlgFunc

        TextBox 10, 10, 120, 150, .joe, ES_MULTILINE Or ES_AUTOVSCROLL Or ES_WANTRETURN            ' Indicates multiline TextBox

     'TextBox 10, 10, 120, 150, .joe, 1 ' indicates multi-line textbox                   

     CancelButton 25, 168, 40, 12  

        OKButton 75, 168, 40, 12

    End Dialog

    Dim Dlg1 As DialogType

    Dlg1.joe  = "The quick brown fox jumped over the lazy dog"

    ' Dialog returns -1 for OK, 0 for Cancel

    button = Dialog( Dlg1 )

    'MsgBox "button: " & button

    If button = 0 Then Exit Sub

 

    MsgBox "TextBox: "& Dlg1.joe

End Sub

 

 

 

Option Buttons and Group Boxes

 

You can have option buttons to allow the user to choose one option from several.  Typically, you would use a group box to surround a group of option buttons, but you can also use a group box to set off a group of check boxes or any related group of controls.

 

 

Begin Dialog GroupSample 31,32,185,96,"Option Button and Check Box"

   OKButton 28,68,40,14

   CancelButton 120,68,40,14

   GroupBox 12,8,72,52,"GroupBox",.GroupBox1

   GroupBox 100,12,72,48,"GroupBox",.GroupBox2

   OptionGroup .OptionGroup1

   OptionButton 16,24,54,8,"OptionButton",.OptionButton1

   OptionButton 16,40,54,8,"OptionButton",.OptionButton2

   CheckBox 108,24,45,8,"CheckBox",.CheckBox1

   CheckBox 108,40,45,8,"CheckBox",.CheckBox2

End Dialog

   Dim Dlg1 As GroupSample

   Button = Dialog (Dlg1)

End Sub

 

Sub Main

    Begin Dialog DialogName1 60, 60, 160, 70

    TEXT 10, 10, 28, 12, "Name:"

    TEXTBOX 42, 10, 108, 12, .nameStr

    TEXTBOX 42, 24, 108, 12, .descStr

    CHECKBOX 42, 38, 48, 12, "&CHECKME", .checkInt

    OKBUTTON 42, 54, 40, 12

    End Dialog

    Dim Dlg1 As DialogName1

    Dialog Dlg1

 

    MsgBox Dlg1.nameStr

    MsgBox Dlg1.descStr

    MsgBox Dlg1.checkInt

End Sub

 

 

The Dialog Function

 

Cypress Enable supports the dialog function.  This function is a user-defined function that can be called while a custom dialog box is displayed.  The dialog  function makes nested dialog boxes possible and receives messages from the dialog box while it is still active.

 

When the function dialog() is called in Enable it displays the dialog box, and calls the dialog function for that dialog.  Enable calls the dialog function to see if there are any commands to execute.  Typical commands that might be used are disabling or hiding a control. By default all dialog box controls are enabled.  If you want a control to be hidden you must explicitly make it disabled during initialization.  After initialization Enable displays the dialog box.  When an action is taken by the user Enable calls the dialog function and passes values to the function that indicate the kind of action to take and the control that was acted upon.

 

The dialog box and its function are connected in the dialog definition.  A “function name” argument is added to the Begin Dialog instruction, and matches the name of the dialog function located in your Enable program.

 

Begin Dialog UserDialog1 60,60, 260, 188, "3", .Enable

 

The Dialog Box Controls

 

A  dialog function needs an identifier for each dialog box control that it acts on. The dialog function uses string identifiers.  String identifiers are the same as the identifiers used in the dialog record.

 

CheckBox 8, 56, 203, 16, "Check to display controls",. Chk1

 

 

The control’s identifier and label are different.  An identifier begins with a period and is the last parameter in a dialog box control instruction. In the sample code above “Check to display controls” is  the label and .chk1 is the identifier.

 

 

The Dialog Function Syntax

 

The syntax for the dialog function is as follows:

 

Function FunctionName( ControlID$, Action%, SuppValue%)

   Statement Block

   FunctionName = ReturnValue

End Function

 

 

All parameters in the dialog function are required.

 

A dialog function returns a value when the user chooses a command button.  Enable acts on the value returned.  The default is to return 0 (zero) and close the dialog box.  If a non zero is assigned the dialog box remains open.  By keeping the dialog box open, the dialog function allows the user to do more than one command from the same dialog box.  Dialog examples ship as part of the sample .bas programs and can be found in your install directory.

 

ControlID$ Receives the identifier of the dialog box control

 

Action  Identifies the action that calls the dialog function.  There are six possibilities, Enable supports the first  4.

Action 1    The value passed before the dialog becomes visible

 

Action 2    The value passed when an action is taken ( i.e. a button is pushed, checkbox is checked etc...)  The controlID$ is the same as the identifier for the control that was chosen

 

Action 3   Corresponds to a change in a text box or combo box.  This value is passed when a control loses the focus (for example, when the user presses the TAB key to move to a different control) or after the user clicks an item in the list of a combo box (an Action value of 2 is passed first).  Note that if the contents of the text box or combo box do not change, an Action value of 3 is not passed.  When Action is 3, ControlID$ corresponds to the identifier for the text box or combo box whose contents were changed.

 

Action 4   Corresponds to a change of focus.  When Action is 4, ControlID$ corresponds to the identifier of the control that is gaining the focus.  SuppValue corresponds to the numeric identifier for the control that lost the focus.  A Dialog function cannot display a message box or dialog box in response to an Action value of 4

 

 

SuppValue receives supplemental information about a change in a dialog box control.  The information SuppValue receives depends on which control calls the dialog function. The following SuppValue values are passed when Action is 2 or 3.