# $language = "VBScript" # $interface = "1.0" ' GetTabByName.py.txt ' ' Description: ' - Shows how to get a reference to a tab object by name/title/caption. ' SecureCRT's Scripting API doesn't have a native GetTabByName() method. ' So, you must iterate over each existing tab checking each tab's caption ' to get a reference to a tab by name. ' ' Last Modified: ' Oct 12, 2018: ' - Initial version ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function GetTabByName(strName) ' Default to returning nothing if we never find a tab by the given name Set GetTabByName = Nothing For nTabIndex = 1 To crt.GetTabCount Set objTab = crt.GetTab(nTabIndex) If objTab.Caption = strName Then Set GetTabByName = objTab Exit Function End If Next End Function ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function GetTabByNameCI(strName) ' Case-insensitive version of this same function Set GetTabByNameCI = Nothing For nTabIndex = 1 To crt.GetTabCount Set objTab = crt.GetTab(nTabIndex) If objTab.Caption = strName Then Set GetTabByNameCI = objTab Exit Function End If If LCase(objTab.Caption) = LCase(strName) Then Set GetTabByNameCI = objTab Exit Function End If Next End Function ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sub Example() strTabTitle = "MyTabTitle" Do strTabTitle = crt.Dialog.Prompt("Please enter desired tab title (case matters)", "Tab title/name?", strTabTitle) If strTabTitle = "" Then Exit Do Set objTab = GetTabByName(strTabTitle) If objTab Is Nothing Then crt.Dialog.MessageBox "Tab '" & strTabTitle & "' was not found." Else objTab.Activate crt.Dialog.MessageBox "Tab #" & objTab.Index & " (""" & objTab.Caption & """) is now active." End If Loop End Sub ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sub ExampleCI() strTabTitle = "mytabtitle" Do strTabTitle = crt.Dialog.Prompt("Please enter desired tab title (case doesn't matter)", "Tab title/name?", strTabTitle) If strTabTitle = "" Then Exit Do Set objTab = GetTabByNameCI(strTabTitle) If objTab Is Nothing Then crt.Dialog.MessageBox "Tab '" & strTabTitle & "' was not found." Else objTab.Activate crt.Dialog.MessageBox "Tab #" & objTab.Index & " (""" & objTab.Caption & """) is now active." End If Loop End Sub Example ExampleCI