HowTos > Dynamically Change the User Interface |
You can dynamically show or hide user interface controls or change the actions associated with the controls.
![]() |
Note: You can manipulate any control that is configured with the UI Designer. InfoConnect does not provide programmatic access to other controls. |
![]() |
This article contains tabbed content that is specific to each terminal type. Be sure the tab for your terminal type is selected. |
Lets' take a look at how to hide the Tools tab on the InfoConnect ribbon for users and display it only for administrators.
Before you open Visual Basic, you'll need to get the identifier for the control you want to access in the InfoConnect UI Designer.
Display controls only for administrators |
Copy Code
|
---|---|
Private Declare Function IsUserAnAdmin Lib "shell32" () As Long Private Sub IbmTerminal_BeforeConnect(ByVal sender As Variant) Dim ui As UiMode Dim control As UiControl Dim userProfile As String Dim position As Long 'Get the UiMode object that contains the controls for the active view. Set ui = ThisFrame.SelectedView.UiMode 'Get the control. The control ID is displayed in the Identifier field on the UI Designer. Set control = ui.GetControlById("toolsTab") 'Hide the tools tab unless the user is an admin If IsUserAnAdmin = 1 Then control.Visible = True Else control.Visible = False End If End Sub |
Display controls only for administrators |
Copy Code
|
---|---|
Private Declare Function IsUserAnAdmin Lib "shell32" () As Long Private Function Terminal_Connecting(ByVal sender As Variant, ByVal ConnectionID As Long, ByVal connnectionType As Attachmate_Reflection_Objects_Emulation_OpenSystems.ConnectionTypeOption, ByVal connectionSettings As Variant) As Boolean Dim ui As UiMode Dim control As UiControl Dim userProfile As String Dim position As Long 'Get the UiMode object that contains the controls for the active view. Set ui = ThisFrame.SelectedView.UiMode 'Get the control. The control ID is displayed in the Identifier field on the UI Designer. Set control = ui.GetControlById("toolsTab") 'Hide the tools tab unless the user is an admin If IsUserAnAdmin = 1 Then control.Visible = True Else control.Visible = False End If Terminal_Connecting = True End Function |
You can dynamically show or hide user interface controls as screens change.
In this example, we'll create an InfoConnect demo session that displays a button that runs a macro only when a specific screen is recognized and hides the button on other screens.
Print out some text on the screen |
Copy Code
|
---|---|
'This macro gets a string from the screen and prints it to the Immediate window Sub CopyData() Dim Data As String Data = ThisIbmScreen.GetText(13, 9, 69) Debug.Print Data End Sub |
Print out some text on the screen |
Copy Code
|
---|---|
'This macro gets the data above the Command prompt and prints it to the Immediate window Sub CopyData() Dim Data As String Data = ThisScreen.GetText2(5, 24, 19, 57) Debug.Print Data End Sub |
![]() |
Note: The active session is automatically configured to use this custom UI file but you'll need to configure any other sessions to use this file instead of the default built-in. You'll also need to deploy the custom file to your users. |
Show or hide control |
Copy Code
|
---|---|
Private Sub IbmScreen_NewScreenReady(ByVal sender As Variant) Dim ui As UiMode Dim control As UiControl Dim screenID As String 'Get the UiMode object that contains the controls for this view. Set ui = ThisView.UiMode 'Get the control. The control ID is displayed in the Identifier field on the UI Designer. Set control = ui.GetControlById("button2") 'Get the text to identify the screen screenID = Trim(ThisIbmScreen.GetText(1, 25, 13)) Debug.Print screenID 'When the appropriate screen is ready, make the control visible If screenID = "INTERNATIONAL" Then control.Visible = True Else control.Visible = False End If End Sub |
Show or hide control |
Copy Code
|
---|---|
Private Sub Screen_ControlKeySent(ByVal sender As Variant, ByVal Key As Attachmate_Reflection_Objects_Emulation_OpenSystems.ControlKeyCode) Dim ui As Attachmate_Reflection_Objects.UiMode Dim control As Attachmate_Reflection_Objects.UiControl Dim Screen As Attachmate_Reflection_Objects_Emulation_OpenSystems.Screen Dim Terminal As Attachmate_Reflection_Objects_Emulation_OpenSystems.Terminal Dim rCode As ReturnCode 'Get the UiMode object that contains the controls for this view. Set ui = ThisView.UiMode 'Get the control. The control ID is displayed in the Identifier field on the UI Designer. Set control = ui.GetControlById("button2") 'Get the Screen and terminal variables. Set Terminal = ThisFrame.SelectedView.control Set Screen = Terminal.Screen 'Wait for the string returned on the screen that has the data, with a timeout of 3000 ms. 'This string is from the recorded macro code. rCode = Screen.WaitForString2("Command> ", 3000) 'Show or hide the control If rCode = 1 Then control.Visible = True Else control.Visible = False End If End Sub |
The button should be visible on the ribbon, in the Macros Group.
These samples use events to control macro execution. The first sample handles the BeforeConnect (IBM) and Connecting (Open Systems) events to set the visibility of the control when the session connects. The second sample handles the NewScreenReady (IBM) and AfterControlKeySent (Open Systems) events to show or hide a control when a specific screen is recognized. For more about handling events and using screen recognition to control macros, see Using InfoConnect Events and Controlling Macro Execution.
These samples show how to show or hide the control. Another option is to enable or disable ("gray out") the control.
'When the appropriate screen is ready, enable the control If screenID = "INTERNATIONAL" Then control.Enabled = True Else control.Enabled = False End If