I have a macro that needs to incorporate a line break when scraping data and exporting to a csv file. I have the macro built, but the line break isn't executing correctly. Does anyone have Attachmate platform macro experience to help me?
Here's my macro that currently has a line break code in it...
'--------------------------------------------------------------------------------
' This macro was created by the Macro Recorder.
' Session Document: "Hogan2023.edp"
' Date: Monday, December 07, 2015 12:59:18
' User: N888098
'--------------------------------------------------------------------------------
' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$
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 = 0 ' 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 1
Open "H:\My Documents\outputfile.csv" For Output As 1
' This section of code contains the recorded events
Sess0.QuickPads("HOGAN SHORTCUT BUTTONS").Visible = True
Sess0.QuickPads("S&S SHORTCUT BUTTONS").Visible = True
Sess0.Screen.Sendkeys("<Clear><Clear>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("RE15<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitForCursor 1,75
Sess0.QuickPads("HOGAN SHORTCUT BUTTONS").Visible = True
Sess0.QuickPads("S&S SHORTCUT BUTTONS").Visible = True
Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitForCursor 8,2
Sess0.QuickPads("HOGAN SHORTCUT BUTTONS").Visible = True
Sess0.QuickPads("S&S SHORTCUT BUTTONS").Visible = True
Sess0.Screen.Sendkeys("x<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Do
CycleDate = Sess0.Screen.Area(2,14,2,23)
TRNPosition = InStr(1, Sess0.Screen.Area(18, 13, 19, 80), "TRN#")
If TRNPosition = 0 Then TRN = "TRN not found"
If TRNPosition > 61 And TRNPosition < 72 Then
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 76 - (TRNPosition + 1)) & Sess0.Screen.Area(19, 13, 19, (12 - (76 - (TRNPosition + 1))))
Else
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 12)
End If
Print #1, CycleDate & "," & TRN
System.TimeoutValue = OldSystemTimeout
Sess0.Screen.Sendkeys("<Pf8>")
Loop Until Sess0.Screen.Area(1,2,1,4) = Sess0.Screen.Area(1,9,1,11)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
CycleDate = Sess0.Screen.Area(2,14,2,23)
TRNPosition = InStr(1, Sess0.Screen.Area(18, 13, 19, 80), "TRN#")
If TRNPosition = 0 Then TRN = "TRN not found"
If TRNPosition > 61 And TRNPosition < 72 Then
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 76 - (TRNPosition + 1)) & Sess0.Screen.Area(19, 13, 19, (12 - (76 - (TRNPosition + 1))))
Else
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 12)
End If
Print #1, CycleDate & "," & TRN
System.TimeoutValue = OldSystemTimeout
Close 1
End Sub
And here are the lines specific to my line break, as shown above in the full macro...
TRNPosition = InStr(1, Sess0.Screen.Area(18, 13, 19, 80), "TRN#")
If TRNPosition = 0 Then TRN = "TRN not found"
If TRNPosition > 61 And TRNPosition < 72 Then
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 76 - (TRNPosition + 1)) & Sess0.Screen.Area(19, 13, 19, (12 - (76 - (TRNPosition + 1))))
Else
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 12)
Here's my macro that currently has a line break code in it...
'--------------------------------------------------------------------------------
' This macro was created by the Macro Recorder.
' Session Document: "Hogan2023.edp"
' Date: Monday, December 07, 2015 12:59:18
' User: N888098
'--------------------------------------------------------------------------------
' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$
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 = 0 ' 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 1
Open "H:\My Documents\outputfile.csv" For Output As 1
' This section of code contains the recorded events
Sess0.QuickPads("HOGAN SHORTCUT BUTTONS").Visible = True
Sess0.QuickPads("S&S SHORTCUT BUTTONS").Visible = True
Sess0.Screen.Sendkeys("<Clear><Clear>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("RE15<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitForCursor 1,75
Sess0.QuickPads("HOGAN SHORTCUT BUTTONS").Visible = True
Sess0.QuickPads("S&S SHORTCUT BUTTONS").Visible = True
Sess0.Screen.Sendkeys("<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.WaitForCursor 8,2
Sess0.QuickPads("HOGAN SHORTCUT BUTTONS").Visible = True
Sess0.QuickPads("S&S SHORTCUT BUTTONS").Visible = True
Sess0.Screen.Sendkeys("x<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Do
CycleDate = Sess0.Screen.Area(2,14,2,23)
TRNPosition = InStr(1, Sess0.Screen.Area(18, 13, 19, 80), "TRN#")
If TRNPosition = 0 Then TRN = "TRN not found"
If TRNPosition > 61 And TRNPosition < 72 Then
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 76 - (TRNPosition + 1)) & Sess0.Screen.Area(19, 13, 19, (12 - (76 - (TRNPosition + 1))))
Else
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 12)
End If
Print #1, CycleDate & "," & TRN
System.TimeoutValue = OldSystemTimeout
Sess0.Screen.Sendkeys("<Pf8>")
Loop Until Sess0.Screen.Area(1,2,1,4) = Sess0.Screen.Area(1,9,1,11)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
CycleDate = Sess0.Screen.Area(2,14,2,23)
TRNPosition = InStr(1, Sess0.Screen.Area(18, 13, 19, 80), "TRN#")
If TRNPosition = 0 Then TRN = "TRN not found"
If TRNPosition > 61 And TRNPosition < 72 Then
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 76 - (TRNPosition + 1)) & Sess0.Screen.Area(19, 13, 19, (12 - (76 - (TRNPosition + 1))))
Else
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 12)
End If
Print #1, CycleDate & "," & TRN
System.TimeoutValue = OldSystemTimeout
Close 1
End Sub
And here are the lines specific to my line break, as shown above in the full macro...
TRNPosition = InStr(1, Sess0.Screen.Area(18, 13, 19, 80), "TRN#")
If TRNPosition = 0 Then TRN = "TRN not found"
If TRNPosition > 61 And TRNPosition < 72 Then
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 76 - (TRNPosition + 1)) & Sess0.Screen.Area(19, 13, 19, (12 - (76 - (TRNPosition + 1))))
Else
TRN = Mid(Sess0.Screen.Area(18, 13, 19, 80), TRNPosition + 4, 12)