I have tried searching but as yet to no avail.
What I am trying to do using reflection 2011, using a macro to log into various systems, then perform a command and to record the response of that command and append it to a text file.
I am a telecoms engineer so all this is making my head hurt.
What I have so far is this, I cant get the savefile to work as I require. All I want is to record the output when the MMS command is run. Then append it to the file and be added to when the next mms is run.
I start the macro from the dmsroutine sub
I am also sure I could have the AN1 AS1 commands read from a text file to shorten my code even more. Yet that at this time is beyond me.
Any tips ?
What I am trying to do using reflection 2011, using a macro to log into various systems, then perform a command and to record the response of that command and append it to a text file.
I am a telecoms engineer so all this is making my head hurt.
What I have so far is this, I cant get the savefile to work as I require. All I want is to record the output when the MMS command is run. Then append it to the file and be added to when the next mms is run.
I start the macro from the dmsroutine sub
I am also sure I could have the AN1 AS1 commands read from a text file to shorten my code even more. Yet that at this time is beyond me.
Any tips ?
Code:
' defines var to pass to other subs
Dim username As String
Dim password As String
Sub savefile()
Dim screenText As String, topRow As String
Dim maxRow As Long, maxCol As Long, fnum As Integer
maxRow = ThisScreen.DisplayRows
maxCol = ThisScreen.DisplayColumns
topRow = ThisScreen.DisplayMemoryTopRow
'Get all the text, starting at the top row of display memory and the first column and ending at the
'maximum row and column
screenText = ThisScreen.GetText3(topRow, 1, maxRow, maxCol, RegionOption_Wrapped, _
TextTranslationOption_NoTranslation)
'Open a file and append the screen text
path = ThisTerminal.SessionFilePath & ".log"
fnum = FreeFile()
Open path For Append As fnum
Print #fnum, screenText
Close #fnum
Terminal_Closing = True
End Sub
Public Sub pwmms()
Const NEVER_TIME_OUT = 0
Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim user, user2, title2, title, defaultValue As String
Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen
LF = Chr(10)
CR = Chr(13)
user = "Enter Username"
title = "Username here you Northan git"
defaultValue = ""
username = InputBox(user, title, defaultValue)
user2 = "Enter Password"
title2 = "Enter Your Password"
defaultValue = ""
password = InputBox(user2, title2, defaultValue)
End Sub
Sub pw()
Const NEVER_TIME_OUT = 0
Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen
LF = Chr(10)
CR = Chr(13)
osCurrentScreen.SendKeys username
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Enter Password" & CR & LF, NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If
osCurrentScreen.SendKeys password
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(" ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If
End Sub
Sub mmscommand()
Const NEVER_TIME_OUT = 0
Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim displayText As String
Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen
LF = Chr(10)
CR = Chr(13)
osCurrentScreen.SendKeys "MMS"
osCurrentScreen.SendControlKey ControlKeyCode_Return
osCurrentScreen.SendControlKey ControlKeyCode_Return
osCurrentScreen.SendControlKey ControlKeyCode_Return
osCurrentScreen.SendKeys "LOGOUT"
Call savefile
osCurrentScreen.SendControlKey ControlKeyCode_Return
End Sub
Sub dmsroutine()
Const NEVER_TIME_OUT = 0
Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen
LF = Chr(10)
CR = Chr(13)
Call pwmms
osCurrentScreen.SendKeys "AN1"
osCurrentScreen.SendControlKey ControlKeyCode_Return
returnValue = osCurrentScreen.WaitForString3("Enter User Name" & CR & LF, NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If
Call pw
Call mmscommand
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & " :-", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If
osCurrentScreen.SendKeys "AS1"
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Enter User Name" & CR & LF, NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If
Call pw
Call mmscommand
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & " :-", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If