Mid(Line4, 5, 4) ' Line4 Returns entire line of the file. 5 is the position where to start. 4 is how many characters to grab.
Example
'Date Created: JUNE 29, 2015
'Date Revised: JUNE 29, 2015
'Title: MAINT_CHG_SIC_CCAN_Loop
'Reading File from C:\Users\USERNAME\Documents\AHK\Batch_Manipulator\Batch_Manipulator_File.txt
Sub MAINT_CHG_SIC_CCAN_Loop()
Dim hostSettleTimeout As Integer
Dim hostSettleTime As Integer
Dim osCurrentScreen As Screen
Dim osCurrentTerminal As Terminal
Dim returnValue As Integer
Dim hiddenTextEntry As String
hostSettleTimeout = 5000
hostSettleTime = 300
Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen
Dim myUser As String
myUser = Environ("username")
'File Delete for Warnings
FilePath = "C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\WarningSICCntrctReport.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(FilePath)) Then
Kill "C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\WarningSICCntrctReport.txt"
End If
' ******** This is for Payables Set Up and IDC clearing.*************************
' Reading File from C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\Batch_Manipulator_File.txt
MyFile = "C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\Batch_Manipulator_File.txt"
Open MyFile For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Input #1, CCANVar, SICVar ' Read into variables.
SICVar = Format(SICVar, String(4, "0"))
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(300)
Call Reset_to_InfoLease_Master_Menu
osCurrentScreen.SendKeys "2"
osCurrentScreen.SendControlKey ControlKeyCode_Enter
osCurrentScreen.SendKeys "3"
osCurrentScreen.SendControlKey ControlKeyCode_Enter
osCurrentScreen.SendKeys "3"
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
Call osCurrentScreen.SendKeys(CCANVar) ' CCAN
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(300)
Call GrabScreen
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(300)
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, Line1
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\GrabScreenFile.txt")
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Line1 = ts.ReadLine ' First Line on File
Line2 = ts.ReadLine ' Second Line on File
Line3 = ts.ReadLine ' Third Line on File
Line4 = ts.ReadLine ' Fourth Line on File
Line5 = ts.ReadLine ' Fifth Line on File
Line6 = ts.ReadLine ' Sixth Line on File
Line7 = ts.ReadLine ' Seventh Line on File
line8 = ts.ReadLine ' Eight Line on File
line9 = ts.ReadLine ' Nineth Line on File
line10 = ts.ReadLine ' Tenth Line on File
line11 = ts.ReadLine ' Eleventh Line on File
Line12 = ts.ReadLine ' Twelveth Line on File
line13 = ts.ReadLine ' Thirteenth Line on File
line14 = ts.ReadLine ' Fourteenth Line on File
line15 = ts.ReadLine ' Fifteenth Line on File
Line16 = ts.ReadLine ' Sixteenth Line on File
line17 = ts.ReadLine ' Seventeenth Line on File
line18 = ts.ReadLine ' Eighteenth Line on File
line19 = ts.ReadLine ' Nineteenth Line on File
Line20 = ts.ReadLine ' Twentyth Line on File
Line21 = ts.ReadLine ' Twenty-First Line on File
Line22 = ts.ReadLine ' Twentyth Line on File
Line23 = ts.ReadLine ' Twenty-First Line on File
line24 = ts.ReadLine ' Twentyth Line on File
ts.Close
If (line9) Like "*Customer*Name*Address*" Then
'Write Warningn Log Errors
Open "C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\WarningSICCntrctReport.txt" For Append As #2 ' Open file for output.
Write #2, "CCAN: " & (CCANVar), "MSG: CCAN does not exist" ' Write comma-delimited data.
Close #2
For x = 1 To 3
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
Next x
osCurrentScreen.SendKeys "/"
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
GoTo EndOfProcess
End If
ByPass_Message_Box
osCurrentScreen.SendKeys "1"
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendKeys "22"
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendKeys "A"
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
Call osCurrentScreen.SendKeys(SICVar) ' SIC CODE
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(300)
Call GrabScreen
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(300)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Line1 = ts.ReadLine ' First Line on File
Line2 = ts.ReadLine ' Second Line on File
Line3 = ts.ReadLine ' Third Line on File
Line4 = ts.ReadLine ' Fourth Line on File
Line5 = ts.ReadLine ' Fifth Line on File
Line6 = ts.ReadLine ' Sixth Line on File
Line7 = ts.ReadLine ' Seventh Line on File
line8 = ts.ReadLine ' Eight Line on File
line9 = ts.ReadLine ' Nineth Line on File
line10 = ts.ReadLine ' Tenth Line on File
line11 = ts.ReadLine ' Eleventh Line on File
Line12 = ts.ReadLine ' Twelveth Line on File
line13 = ts.ReadLine ' Thirteenth Line on File
line14 = ts.ReadLine ' Fourteenth Line on File
line15 = ts.ReadLine ' Fifteenth Line on File
Line16 = ts.ReadLine ' Sixteenth Line on File
line17 = ts.ReadLine ' Seventeenth Line on File
line18 = ts.ReadLine ' Eighteenth Line on File
line19 = ts.ReadLine ' Nineteenth Line on File
Line20 = ts.ReadLine ' Twentyth Line on File
Line21 = ts.ReadLine ' Twenty-First Line on File
Line22 = ts.ReadLine ' Twentyth Line on File
Line23 = ts.ReadLine ' Twenty-First Line on File
line24 = ts.ReadLine ' Twentyth Line on File
ts.Close
If (line24) Like "*[2750]*SIC*Code*already*exists*" Then
'Write Warningn Log Errors
Open "C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\WarningSICCntrctReport.txt" For Append As #2 ' Open file for output.
Write #2, "CCAN: " & (CCANVar), "MSG: [2750] SIC Code already exists" ' Write comma-delimited data.
Close #2
For x = 1 To 3
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
Next x
osCurrentScreen.SendKeys "/"
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
GoTo EndOfProcess
ElseIf (line24) Like "*Enter*valid*code*Table*<return>*" Then
'Write Warningn Log Errors
Open "C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\WarningSICCntrctReport.txt" For Append As #2 ' Open file for output.
Write #2, "CCAN: " & (CCANVar), "Enter valid code, '=' - Table, <return>" ' Write comma-delimited data.
Close #2
For x = 1 To 3
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
Next x
osCurrentScreen.SendKeys "/"
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
GoTo EndOfProcess
Else
SICVerifyProcess:
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(300)
Call GrabScreen
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(300)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Line1 = ts.ReadLine ' First Line on File
Line2 = ts.ReadLine ' Second Line on File
Line3 = ts.ReadLine ' Third Line on File
Line4 = ts.ReadLine ' Fourth Line on File
Line5 = ts.ReadLine ' Fifth Line on File
Line6 = ts.ReadLine ' Sixth Line on File
Line7 = ts.ReadLine ' Seventh Line on File
line8 = ts.ReadLine ' Eight Line on File
line9 = ts.ReadLine ' Nineth Line on File
line10 = ts.ReadLine ' Tenth Line on File
line11 = ts.ReadLine ' Eleventh Line on File
Line12 = ts.ReadLine ' Twelveth Line on File
line13 = ts.ReadLine ' Thirteenth Line on File
line14 = ts.ReadLine ' Fourteenth Line on File
line15 = ts.ReadLine ' Fifteenth Line on File
Line16 = ts.ReadLine ' Sixteenth Line on File
line17 = ts.ReadLine ' Seventeenth Line on File
line18 = ts.ReadLine ' Eighteenth Line on File
line19 = ts.ReadLine ' Nineteenth Line on File
Line20 = ts.ReadLine ' Twentyth Line on File
Line21 = ts.ReadLine ' Twenty-First Line on File
Line22 = ts.ReadLine ' Twentyth Line on File
Line23 = ts.ReadLine ' Twenty-First Line on File
line24 = ts.ReadLine ' Twentyth Line on File
ts.Close
Dim SICVerify As String
SICVerify = Mid(Line4, 5, 4) ' Line4 Returns entire line of the file. 5 is the position where to start. 4 is how many characters to grab.
If (SICVerify) = (SICVar) Then
For x = 1 To 6
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
Next x
ElseIf (Line1) Like "*InfoLease*Master*Menu*" Then
GoTo EndOfProcess
ElseIf (Line7) Like "*Bank*Account*Information*" Then
GoTo EndOfProcess
Else
osCurrentScreen.SendKeys "D"
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
Call osCurrentScreen.SendKeys(SICVerify) ' First SIC
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(70)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
osCurrentScreen.SendControlKey ControlKeyCode_Enter
'Wait for host to 'be quiet' before continuing
returnValue = osCurrentScreen.WaitForHostSettle(50)
GoTo SICVerifyProcess
End If
End If
EndOfProcess:
Loop
Close #1 ' Close file.
'Open Warning Report
RetVal = Shell("C:\Windows\Notepad.exe C:\Users\" & myUser & "\Documents\AHK\Batch_Manipulator\WarningSICCntrctReport.txt", 1) ' Open Warning Report.
End Sub