Show Contents / Index / Search

The SmartUx Controls

Let’s take a look at how to set up some screen decorations in VBA. We’ll start with the basic code for each control and then pull the controls together into a working demo application in the SmartUxDemo.

The SmartUx Button Control

Use the SmartUx button control to place buttons on your session screen. You can use the buttons as simple labels or messages. You can also handle the ButtonClicked event to perform a variety of actions.

This sample creates a button that opens or closes the Reflection Scratch Pad.

‘Declare a global ButtonDecoration with events to bind the button to the buttonclick event

Dim WithEvents button As SmartButton

Private Sub DrawButton()

   'Create the button

   Set button = New SmartButton

   'Define the button position, dimensions, and text label

   button.startRow = 3

   button.StartColumn = 53

   button.EndRow = 3

   button.EndColumn = 65

   button.ToolTipText = "Hide Scratch Pad"

   button.text = "Hide Notes"

   'Add the button to the view

   ThisView.AddSmartControl button

End Sub

'Handle the ButtonClicked event to toggle the scratch pad visibility.

Private Sub button_ButtonClicked(ByVal sender As Variant)

'toggle the scratch pad on and off

   If (ThisIbmTerminal.Productivity.ScratchPadPanelVisible) Then

     ThisIbmTerminal.Productivity.ScratchPadPanelVisible = False

     button.text = "Show Notes"

   Else

     ThisIbmTerminal.Productivity.ScratchPadPanelVisible = True

     button.text = "Hide Notes"

   End If

End Sub

When we click our new button, it toggles the scratch pad on and off.

The Dropdown Control

The second screen of our demo has an unmarked command field. To advance to the application, users need to enter the name of the program in this field. We’ll add a drop down selection list that allows users to choose an application.

'Add a global DropDown variable

Dim WithEvents dropDown As SmartDropDown

Private Sub DrawDropDown()

   'Creates a DropDown list decoration and adds it to the view

  

   Set dropDown = New SmartDropDown

   'Set the dimensions for this control

   dropDown.startRow = 8

   dropDown.StartColumn = 1

   dropDown.EndRow = 8

   dropDown.EndColumn = 17

   'Add the list items

   dropDown.AddText ("ISPF Options")

   dropDown.AddText "Sales Reports"

   dropDown.AddText ("Schedules")

   'Add the control to the View

   ThisView.AddSmartControl dropDown

End Sub

In the ValueChanged event, we enter the commands for the selected item in the command field. Before the Transmit control key is sent, the dropBox decoration is removed from the view so that it doesn’t appear on the next screen.

Note: If you don’t want to display a SmartUx control on the next screen, you’ll need to remove it before the screen changes.

Private Sub dropDown_ValueChanged(ByVal sender As Variant, ByVal value As String)

   Dim retVal, Number

   Number = dropDown.SelectedIndex

   'Enter the selected command in the command field

   Select Case Number

      Case 0

         retVal = ThisIbmScreen.PutText2("ISPF", 23, 1)

      Case 1

         retVal = ThisIbmScreen.PutText2("KAYAK", 23, 1)

      Case 2

         retVal = ThisIbmScreen.PutText2("PROFS", 23, 1)

      Case Else

         ThisIbmScreen.PutText2("ISPF", 23, 1) 'Default to the first item

   End Select

   'Remove the control from the View

   ThisView.RemoveSmartControl dropDown

   'Send the control key to advance the screen

   ThisIbmScreen.SendControlKey (ControlKeyCode_Transmit)

End Sub

This demo displays the commands as list items. In our final demo, we’ll use more descriptive options.

The RequiredField and Border Controls

The Reflection API provides both RequiredField and Border SmartUx controls. The only difference is the red outline on the required field.

'Declare a global ButtonDecoration with events

Dim WithEvents reqField As SmartRequiredField

Private Sub DrawRequiredField()

   Set reqField = New SmartRequiredField

   'Set the field dimensions and tooltip

   reqField.startRow = 20

   reqField.StartColumn = 2

   reqField.endRow = 21

   reqField.EndColumn = 34

   reqField.ToolTipText = "Required Field"

   'Add the field to the view

   ThisView.AddSmartControl reqField

End Sub

Private Sub DrawFieldBorder()

Set commandField = New SmartBorder

'Set the field dimensions and tooltip

commandField.startRow = 23

commandField.StartColumn = 16

commandField.endRow = 23

commandField.EndColumn = 34

commandField.ToolTipText = "Command Field"

'Add the field to the view

ThisView.AddSmartControl commandField

End Sub

Now we’ll use the Deactivated event to perform a simple validation when the tab position is moved out of the required field.

Private Sub reqField_Deactivated(ByVal sender As Variant)

   Dim rtnVal As ReturnCode

   'Move the cursor to the first column in the field

   If Len(Trim(ThisIbmScreen.GetFieldText(21, 16))) < 5 Then

      rtnVal = ThisIbmScreen.MoveCursorTo1(21, 16)

   End If

End Sub

Add a date picker

The date picker control allows users to select dates from a calendar.

The format that is displayed on the date picker and in the values sent to the value changed event is set with the DateMask property. (This property uses Microsoft .NET date and time specifiers.)

'Add a global date chooser variable with events binds it to the ValueChanged event.

Dim WithEvents cal As DateChooserDecoration

'Draw the calendar

Sub DrawCalendar()

   Set calendar = New SmartDatePicker

   'Set the calendar control dimensions

   calendar.startRow = 20

   calendar.StartColumn = 1

   calendar.EndRow = 20

   calendar.EndColumn = 15

   

   'Set the displayed value to the international date format

   calendar.DateMask = "yyyy/MM/dd"

   

   'Add the calendar to the control

   ThisView.AddSmartControl calendar

   

End Sub

The value of the selected date is sent to the ValueChanged event.

Private Sub calendar_ValueChanged(ByVal sender As Variant, ByVal value As String)

   'Display the year of the selected date

   MsgBox "Date: " & DatePart("yyyy", value)

End Sub