Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sess0 is Nothing and something else strange.

Status
Not open for further replies.

JasonUSC1

Technical User
Jul 31, 2014
1
US
I am a little reluctant to ask because I am afraid of the implications, but I need to get this done.

Back story:
My company has been using some macros for Attachmate for years and we are going through a conversion to Windows 7
We have an intern who was given Windows 7 and he kept getting an error when he would try to run the macro.
I have experience with Macros for Excel so I was asked if could take a look.
I quickly saw that an input file was on a drive not mapped to my computer (I am now on Windows 7 too) so I changed to path to reflect it and the macro worked fine.
I tried to get the intern to run it so I emailed him the .ebm file and when he tried to open the file it was blank.
I tried to open the file on my computer from the local drive where I saved it and it was blank too.
I was able to finally send him a .txt file and have him copy it into the Macro editor and run it but he got "Could not create the Session object. Stopping macro playback." (The same error he got before).
I found the segment of code that caused the error and I do not know how to fix it.

' Set the default wait timeout value
g_HostSettleTime = 0015 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


The user does have a session open and is signed in.

Does anyone know how to fix this problem?
Any ideas on why I can edit a macro and save it, but when I open it again it is blank?


Full Code:


' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Declare Sub PrtScr32
Declare Sub Clsprt32
Declare Sub Opnprt32



' Dimension macro variables and objects
Dim rc%, row%, MaxColumns%, MaxRows%, filenum%
Dim Screenbuf$, linebuf$, FileName$
Dim System As Object
Dim Session as Object

Sub PrtScr32

' Get the main system object
Set System = CreateObject("EXTRA.System")
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Aborting macro playback."
Stop
End If

' Get the necessary Session Object
Set Session = System.ActiveSession
If (Session is Nothing) Then
Msgbox "Could not create the Session object. Aborting macro playback."
Stop
End If

' Determine the size of the Presentation Space
MaxRows% = Session.Screen.Rows()
MaxColumns% = Session.Screen.Cols()

' Initialize variables to hold screen information
Screenbuf$ = ""
linebuf$ = Space$ (MaxColumns%)

' Copy the Presentation space
For row% = 1 to MaxRows%
' Get a row of data from the host screen
linebuf$ = Session.Screen.Area(row%, 1, row%, MaxColumns%, , xBlock)

' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next


' Print the screen with a form feed
Print #filenum%, screenbuf$; Chr$ (12)


End Sub


Sub Opnprt32

' Get the next available file number
filenum% = FreeFile


FileName$ = "\\Server\RPT_HIST ALL2.txt"
Open FileName$ For Output as filenum%
End Sub


Sub Clsprt32
'Close printer
Close filenum%

End Sub



Sub Main()

'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system object
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 0015 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)




'** close any existing input files that might be left open

CLOSE


Open "\\server\INPT2.txt" for input as #1



Call Opnprt32
print #2, "PRODUCED FROM IMI2 HIST RPT 2.ebm|"
print #2, "CONTROL ACCOUNTS "
'
SDATE = Format(Month(Date),"00") & Format(Day(Date),"00") & Right(YEAR(Date),2)
SDATE = InputBox("Enter Desired Date as MMDDYY if different than the default below",,SDATE)
print #2, "TRANSACTIONS DATED : " & Left(SDATE,2) & "/" & Mid(SDATE,3,2) & "/" & RIGHT(SDATE,2)
print #2,
print #2,

'************************************************
'******Text file parsed into variables during loop

DO
Record_Counter = Record_Counter + 1
LINE INPUT #1, INPUTRECORD$
ACCTNO = mid(INPUTRECORD$,1,10)
MINBAL = val(mid(INPUTRECORD$,11,20))
TRANCount = 0
HISTSCREEN = 0
LASTSCREEN = " "
DBCK = "00"
SROW = 0
DTRAN = 0
CTRAN = 0
DAMT = 0
CAMT = 0


'***************************************************************
'******Keystrokes sent to SAA screen to inquire on account
'*****Check TARGET Value

Sess0.Screen.Sendkeys("<CLEAR>")
Sess0.Screen.Sendkeys("IMI1")
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.Sendkeys(ACCTNO)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
NI = Sess0.Screen.Area(8,80,8,80)
IF NI = "-" THEN
AVAIL = Sess0.Screen.Area(8,66,8,79)*-1
ELSE
AVAIL = Sess0.Screen.Area(8,66,8,79)
END If
STATUS = Sess0.Screen.Area(5,12,5,32)
NI = Sess0.Screen.Area(17,80,17,80)
IF NI = "-" THEN
MTDAVG = Sess0.Screen.Area(17,66,17,79)*-1
ELSE
MTDAVG = Sess0.Screen.Area(17,66,17,79)
END If
RTNMSG = Sess0.Screen.Area(24,21,24,70)
ACCTNO2 = Sess0.Screen.Area(3,17,3,30)
CUSTNAME = Sess0.Screen.Area(6,2,6,40)
TIN = Sess0.Screen.Area(18,37,18,46)
NI = Sess0.Screen.Area(9,80,9,80)
IF NI = "-" THEN
LDGR = val(Sess0.Screen.Area(9,66,9,79)*-1)
ELSE
LDGR = val(Sess0.Screen.Area(9,66,9,79))
END If
ERRMSG = Sess0.Screen.Area(24,21,24,31)

IF ERRMSG <> "REC NOT FND" THEN
print #2, ACCTNO2 & "|" & CUSTNAME & "|TIN: " & TIN & "|Available Bal: " & Format(AVAIL,"Currency") & "|MTD AVG BAL: " & Format(MTDAVG, "Currency") & "|STATUS:" & STATUS
Sess0.Screen.Sendkeys("<HOME>")
Sess0.Screen.Sendkeys("IMI2")
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys(ACCTNO2)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Row = 11
Sess0.Screen.Col = 37
Sess0.Screen.Sendkeys(SDATE)
Sess0.Screen.Row = 11
Sess0.Screen.Col = 61
Sess0.Screen.Sendkeys(SDATE)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
LASTSCREEN = Sess0.Screen.Area(24,21,24,21)
HISTSCREEN = Sess0.Screen.Area(1,15,1,18)
IF HISTSCREEN = "IMI2" THEN
print #2, "|TRAN DESCRIPTION|DATE TYPE|DEBIT AMOUNT|CREDIT AMOUNT|" & RTNMSG
IF LASTSCREEN = "N" THEN
print #2, " |NO TRANSACTIONS FOUND |Ledger Bal:||" & Format(LDGR,"Currency")
print #2, " ||Minimum Bal: ||" & Format(MINBAL,"Currency")
If LDGR < MINBAL THEN
print #2, "||| ACCOUNT LEDGER BAL OF " & Format(LDGR,"Currency") & "|IS UNDER MINIMUM BAL" & Format(MINBAL,"Currency")
END If
print #2, " "
print #2, " "
ELSE
WHILE LASTSCREEN = " "
SROW = 8
FOR TRANCount = 0 to 13
DBCK = Sess0.Screen.Area(SROW,54,SROW,55)
IF DBCK <> " " THEN
PDATE = Sess0.Screen.Area(SROW,4,SROW,8)
IF DBCK = "DB" OR DBCK = "CK" THEN
DTRAN = DTRAN + 1
TAMT = Sess0.Screen.Area(SROW,39,SROW,52)
DAMT = DAMT + TAMT
TDESC = Sess0.Screen.Area(SROW,57,SROW,75)
print #2, " |" & TDESC & " |" & PDATE & " " & DBCK & " |" & Format(TAMT, "Currency")
END If
IF DBCK = "DP" OR DBCK = "CR" THEN
CTRAN = CTRAN + 1
TAMT = Sess0.Screen.Area(SROW,39,SROW,52)
CAMT = CAMT + TAMT
TDESC = Sess0.Screen.Area(SROW,57,SROW,75)
print #2, " |" & TDESC & " |" & PDATE & " " & DBCK & " | |" & Format(TAMT, "Currency")
END If
END If
SROW = SROW + 1
PDATE = 0
TAMT = 0
TDESC = 0
DBCK = 0
NEXT TRANCount
Sess0.Screen.Sendkeys("<Pf1>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
LASTSCREEN = Sess0.Screen.Area(24,21,24,21)
TRANCount = 0

WEND
print #2, " ||Total" & " | " & Format(DAMT, "Currency") & " | " & Format(CAMT, "Currency")
print #2, " ||Ledger Bal: ||" & Format(LDGR,"Currency")
print #2, " ||Minimum Bal: ||" & Format(MINBAL,"Currency")
If LDGR < MINBAL THEN
print #2, "||| ACCOUNT LEDGER BAL OF " & Format(LDGR,"Currency") & "|IS UNDER MINIMUM BAL" & Format(MINBAL,"Currency")
END If
print #2, " "
print #2, " "
END If
END If
ELSEIF ERRMSG = "REC NOT FND" THEN
Sess0.Screen.Sendkeys("<CLEAR>")
Sess0.Screen.Sendkeys("STI1")
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.Sendkeys(ACCTNO)
Sess0.Screen.Sendkeys("<EraseEOF>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
NI = Sess0.Screen.Area(6,80,6,80)
IF NI = "-" THEN
AVAIL = Sess0.Screen.Area(8,66,8,79)*-1
ELSE
AVAIL = Sess0.Screen.Area(8,66,8,79)
END If
STATUS = Sess0.Screen.Area(16,2,16,11)
RTNMSG = Sess0.Screen.Area(24,21,24,70)
ACCTNO2 = Sess0.Screen.Area(3,18,3,31)
CUSTNAME = Sess0.Screen.Area(6,2,6,40)
TIN = Sess0.Screen.Area(13,15,13,24)
NI = Sess0.Screen.Area(9,80,9,80)
IF NI = "-" THEN
LDGR = val(Sess0.Screen.Area(9,66,9,79)*-1)
ELSE
LDGR = val(Sess0.Screen.Area(9,66,9,79))
APPL = "ST"
END If
Sess0.Screen.Sendkeys("<Pf1>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
NI = Sess0.Screen.Area(12,50,12,50)
IF NI = "-" THEN
YTDAVG = Sess0.Screen.Area(12,36,12,49)*-1
ELSE
YTDAVG = Sess0.Screen.Area(12,36,12,49)
END If

ERRMSG = Sess0.Screen.Area(24,21,24,31)
IF ERRMSG <> "ACCOUNT NOT" THEN
print #2, ACCTNO & "|" & CUSTNAME & "|TIN: " & TIN & "|Available Bal: " & Format(AVAIL,"Currency") & "|YTD AVG BAL: " & Format(YTDAVG, "Currency") & "|STATUS:" & STATUS

Sess0.Screen.Sendkeys("<HOME>")
Sess0.Screen.Sendkeys("STI2")
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys(ACCTNO2)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Row = 12
Sess0.Screen.Col = 37
Sess0.Screen.Sendkeys(SDATE)
Sess0.Screen.Row = 12
Sess0.Screen.Col = 61
Sess0.Screen.Sendkeys(SDATE)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
LASTSCREEN = Sess0.Screen.Area(24,21,24,21)
HISTSCREEN = Sess0.Screen.Area(1,15,1,18)
IF HISTSCREEN = "STI2" THEN
print #2, "|TRAN DESCRIPTION|DATE TYPE|DEBIT AMOUNT|CREDIT AMOUNT|" & RTNMSG
IF LASTSCREEN = "N" THEN
print #2, " |NO TRANSACTIONS FOUND |Ledger Bal:||" & Format(LDGR,"Currency")
print #2, " ||Minimum Bal: ||" & Format(MINBAL,"Currency")
If LDGR < MINBAL THEN
print #2, "||| ACCOUNT LEDGER BAL OF " & Format(LDGR,"Currency") & "|IS UNDER MINIMUM BAL" & Format(MINBAL,"Currency")
END If
print #2, " "
print #2, " "
ELSE

SROW = 8
FOR TRANCount = 0 to 13
DBCK = Sess0.Screen.Area(SROW,38,SROW,38)
IF DBCK <> " " THEN
PDATE = Sess0.Screen.Area(SROW,40,SROW,47)
IF DBCK = "D" THEN
DTRAN = DTRAN + 1
TAMT = Sess0.Screen.Area(SROW,23,SROW,36)
DAMT = DAMT + TAMT
TDESC = Sess0.Screen.Area(SROW,49,SROW,86)
print #2, " |" & TDESC & " |" & PDATE & " " & DBCK & " |" & Format(TAMT, "Currency")
END If
IF DBCK = "C" THEN
CTRAN = CTRAN + 1
TAMT = Sess0.Screen.Area(SROW,23,SROW,36)
CAMT = CAMT + TAMT
TDESC = Sess0.Screen.Area(SROW,49,SROW,86)
print #2, " |" & TDESC & " |" & PDATE & " " & DBCK & " | |" & Format(TAMT, "Currency")
END If
END If
SROW = SROW + 1
PDATE = 0
TAMT = 0
TDESC = 0
DBCK = 0
NEXT TRANCount
TRANCount = 0


print #2, " ||Total" & " | " & Format(DAMT, "Currency") & " | " & Format(CAMT, "Currency")
print #2, " ||Ledger Bal: ||" & Format(LDGR,"Currency")
print #2, " ||Minimum Bal: ||" & Format(MINBAL,"Currency")
If LDGR < MINBAL THEN
print #2, "||| ACCOUNT LEDGER BAL OF " & Format(LDGR,"Currency") & "|IS UNDER MINIMUM BAL" & Format(MINBAL,"Currency")
END If
print #2, " "
print #2, " "
END IF
END IF
END IF
END IF

IF ERRMSG = "ACCOUNT NOT" THEN
RTNMSG = Sess0.Screen.Area(24,21,24,50)
print #2, ACCTNO & " |" & RTNMSG
print #2, " "
print #2, " "
END IF


'********************************************************************
'********Saves return code of change to logging area





System.TimeoutValue = OldSystemTimeout



IF EOF(1) THEN

msgbox(Record_Counter & " Records Processed, Please Review Log File for Errors")

Exit Do

END IF

Loop



Close



System.TimeoutValue = OldSystemTimeout



End Sub
 
Try opening the Macro editor and using the "Step" function (which is F10 or under Run>Step" and seeing exactly what line your error is on.

I would also change the Milliseconds to slow the macro down a little and see if the makes a difference.

 
Whenever you SendKeys a command that requests data ASYNCHRONOUSLY from your system, you have no way of knowing EXACTLY how long to wait. It could be less than a second; it could be a minute, an hour. Maybe there's a TRANS LTERM STOP!!!

Waiting some fixed period of time is like pre determining, before you get into your car to drive to work, just how long you'll stop & wait at each intersection before proceeding. How ridiculous!!!

After each send, wait IN A LOOP until the system returns a signal that the data transfer has completed. Like WaitForCursor at the screen rest coordinates. When the cursor appears, exit the loop.
 
SkipVought, can you expand on this a little please? This may improve my macro writing. Perhaps something like I have written below?

Do Until Sess0.Screen.GetString(X, X, X) = "WHATEVER TEXT I WANT"
Application.Wait (Now + TimeValue("0:00:01"))
Loop
 
Your code presupposes that you already know some text. In most cases, one would not know, and therefore I prefer using WaitForCursor at the screen's rest coordinates
Code:
Do Until Sess0.Screen.WaitForCursor(r, c) 
   DoEvents
Loop
 
Don't you still have to know where the screen's rest coordinates are? For each screen in our Extra! program, there seems to be a different one. Is yours normally the same?
 
Each screen can be different.

I happen to do ALL my vb coding in Excel, as I'm getting data from a list in Excel to drive some process and grabbing data from each screen and putting it into Excel for some further processing.

Furthermore, I store screen properties fro every screen I access, that describes all the fields, their data type, start coordinates, field length, row from/thru for tabular data, so YES, I know the screen rest coordinates of each screen and a LOT more!
 
How do you go about storing screen properties? Seems like that would be a helpful thing to know!!

BTW, thanks for all the help
 
As I previously stated, I do ALL my vb coding in Excel. I have a workbook with a sheet that contains a table defining all the screens I use. I have developed functions that aid in processing and parsing the data from any given screen. Then I have a sheet for each screen where I dump all the data from the screen. Yes, I get ALL the data. Then in a post process, I'll zero in on the particular data elements from the screen that I'm interested in.
 
Don't you still have to know where the screen's rest coordinates are?

the way i handle this is to move the cursor to 24,80 before any transaction. i pick 24,80 because i know all my screens will never be at 24,80 after any transaction.
Code:
Do    
[indent][/indent]DoEvents
Loop until sess.row <> 24 and sess.col <> 80

the drawback is this can be an endless loop; you can add a timer to exit the loop.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top