INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Reflection VBA help

Reflection VBA help

(OP)
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 ? :)

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 

RE: Reflection VBA help

Hi,

What does happen when you run your code?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Reflection VBA help

(OP)
It does record, just it records everything. I just want the response from the MMS command that I send. :)

RE: Reflection VBA help

I have not had any experience with Attachmate Reflection, rather Attachment Extra. The Extea VB editor was a Yugo compared to the Cadillac Excel VBA editor, which I used exclusively since I normally scraped screens to an Excel sheet/table.

So I could use a code BREAK to examine variable contents and STEP through the code statements one at a time to observe what was happening.

So what tools do you have at hand to do such an examination?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Reflection VBA help

(OP)
None, as all I have is the reflection 2011 :(.
we don't get provided with anything more technical lol. (They don't trust us lol)

I will carry on looking for ways to output to file the display output, there must be a way.

RE: Reflection VBA help

When you say that "it records everything" exactly what does everything mean?

You have to understand that we don't know what you are seeing or experiencing at your screen. Help us out here.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Reflection VBA help

(OP)
Ok as the macro steps through, what it does is log into each system, AV1 etc,
Then runs a command on that system called MMS
What I am getting is a log of everything, from the start of the script.

What I am after is just to record the output of the MMS command and append that to a text file.
So what this does is
Asks for username/password
Then enters the switch identifier i.e. AV1
Enters the username/password
As it logs in you get wall of text on the reflection terminal, the usual stuff of unauthorized access will be prosecuted etc.
Then the script send an MMS command.
Its the response from the MMS command I want to append to a text file. Just that response.
Then it logs off and goes to the next switch.
What I am getting is a file that contains the complete screen history. Walls of text etc.
The thing is I have 79 switches to go through. So a text file with the entire record of the screen output would be very large.
Is this possible, can you trigger ThisScreen.GetText to start when it sees the MMS command ?

What I have been trying so far is using this

CODE -->

Sub PrintScreenToFile()
Dim sText As String
Dim sFilename As String
Dim sUserProfile As String
Dim i As Integer
Dim rows As Integer
Dim cols As Integer
rows = ThisScreen.DisplayRows
cols = ThisScreen.DisplayColumns

'collect screen data....
For i = 1 To rows
sText = sText & ThisScreen.GetText(i, 1, cols) & vbCrLf
Next

'determine where "My Documents" is located, and prompt for filename
sUserProfile = Environ("USERPROFILE")
sFilename = sUserProfile & "\My Documents\HostScreen.txt"


If sFilename <> "" Then
On Error GoTo handler
Open sFilename For Output As #1
Print #1, sText
Close #1
End If

Exit Sub

handler:
MsgBox Err.Description
Reset

End Sub 

I am no programmer I am a voice comms engineer lol

RE: Reflection VBA help

Quote:

can you trigger ThisScreen.GetText to start when it sees the MMS command ?

The answer is, "a definite maybe!"

What is the EVENT that coincides with the appearance of "the MMS command"?

So far your explanations are not very clear.

You get all this undesired output UNTIL....

What is it that identifies that THIS IS THE PLACE TO START and THIS IS THE PLACE TO END?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Reflection VBA help

(OP)
Ok the response on the terminal is

CODE -->

*************************************************************
**                                                         **
**             This is a private database.                 **
**        All activity is subject to monitoring.           **
**   Any UNAUTHORIZED access or use is PROHIBITED, and     **
**             may result in PROSECUTION.                  **
**                                                         **
*************************************************************


2011/07/20 21:15 *** -  AVON 5 - (AV5) - ISN09 ***                 
>mms
Entering profile...
... Profile Ends
MAPCI:
MTC:
TRKS:
STAT:
0    2W     GC MMTELE7Q931         30     0     0    30   100
1    2W     GC CTS_01_Q931         30     0     0    30   100
2    2W     GC MMTELE8Q931         30     0     0    30   100
3    2W     GC MMTELE9Q931         30     0     0    30   100
4    2W     GC MMTELE10Q931        30     0     0    30   100
5    2W     GC MMTELE11Q931        30     0     0    30   100
6    2W     GC MMTELE12Q931        30     0     0    30   100
7    2W     GC HENRIQUEG_Q931       8     0     0     8   100
NO SUCH TRUNK GROUP
NO SUCH TRUNK GROUP
NO SUCH TRUNK GROUP
NO SUCH TRUNK GROUP
CI:
> 

All I want to do is capture between :-
2011/07/20 21:15 *** - AVON 5 - (AV5) - ISN09 ***
and
CI:

RE: Reflection VBA help

Are you INCLUDING the row with the date?

Is the key value...

>mms

...on the row following the date?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Reflection VBA help

(OP)
It would be nice, if not no worries, it would be easier to identify them in the text file, if that makes sense,

Or from the MMS command to the CI: if its easier.

Thanks for this its just been bugging me for days now.

RE: Reflection VBA help

Would you please answer my questions explicitly.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Reflection VBA help

(OP)
Thinking on it, the
>MMS
Would be the key value to start the capture to file

>LOGOUT
To end the capture to file.
Its not shown above but it will be there.(I missed it off when I copied it across.)

Just slap me if that's not clear.


RE: Reflection VBA help

1) Please copy your screen and paste again.

2) Will this data ALWAYS be only on ONE screen?

3) So if I understand, your program will be cycling through many screens of useless data until it happens on >mms and following, at which time, you want your program to capture the data as stated and QUIT?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close