Jump to content
Sign in to follow this  
FrozenTeeth

Error copying file? HELP!

Recommended Posts

FrozenTeeth

I have a program that ends in the same place everytime. Here is the code. The second code section shows where the issue is. it bombs after coping the file. I have also attached the screen shot of the error and the log file that is getting created. This program would need to be modified heavly if you want to try and run it as it looks for specific files in specific areas. And the SQL stuff :idea: I can not figure out why it bombs after the file copy it waits a few seconds then runs a batch file. The batch file never runs. I have checked the security of all the file/folders and everything is Domain administrator. The user running the script is the Domain Administrator account.

#NoTrayIcon
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\Icons\Iconshock_tiny_animals_vista_icons\ico\elephant.ico
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_cvsWrapper=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>
#include <Date.au3>
#include <file.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Process.au3>
#include <String.au3>
#include <_sql.au3>
Opt('MustDeclareVars', 1)
;
;make sure only one is running on local computer at a time!
;
If _Singleton("5250_new", 1) = 0 Then
    MsgBox(0, "Warning", "An occurence of 5250_new is already running. Exiting.")
    Exit
EndIf
;
MsgBox(64, "5250 Starting", "Starting TotaleChecks Import")
;
;error functions
;
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $HexNumber, $oMyRet, $tTime
;##################################
; EMAIL Variables
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $SmtpServer, $FromAddress, $FromName, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $HexNumber
$SmtpServer = "192.168.0.123" ; address for the smtp-server to use - REQUIRED
$FromName = "5250" ; name from who the email was sent
$FromAddress = "myemail@email.com" ; address from where the mail should come
$ToAddress = "email@email.com" ; destination address of the email - REQUIRED
$Subject = "Notification from: " & @ScriptName ; subject from the email - can be anything you want it to be
$Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = "" ; the file you want to attach- leave blank if not needed
$CcAddress = "super@mail.com" ; address for cc - leave blank if not needed
$BccAddress = "" ; address for bcc - leave blank if not needed
$Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
$Username = "mis" ; username for the account used from where the mail gets sent - REQUIRED
$Password = "daisy5668" ; password for the account used from where the mail gets sent - REQUIRED
$IPPort = 25 ; port used for sending the mail
$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS
;~ $IPPort=465                          ; GMAIL port used for sending the mail
;~ $ssl=1                               ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;
;Dates
;
Global $MyDate, $Today, $todayName, $MyTime, $dd, $yy, $mm, $yesterdaydd, $yesterdaydate, $dateyyyymmdd, $dateprevyyyymmdd, $NCATPrevDate, $dateThreeDaysAgo, $dateThreeDaysAgoDD, $dateThreeDaysAgoMM, $dateThreeDaysAgoYY
Global $yesterdayMM, $yesterdayYY, $dateTwoDaysAgo, $dateTwoDaysAgoDD, $dateTwoDaysAgoMM, $dateTwoDaysAgoYY, $twoweeksago, $twoweeksagoYYYYMMDD, $todayMMDDYY
Global $5250BackupFilename, $fc, $sDir, $sFile, $sCommand, $todayMMDD, $missingboolean
$Today = _NowCalcDate()
_DateTimeSplit($Today, $MyDate, $MyTime)
$todayMMDDYY = StringFormat("%02i%02i%s", $MyDate[2], $MyDate[3], StringRight($MyDate[1], 2))
$todayMMDD = StringFormat("%02i%02i%s", $MyDate[2], $MyDate[3])
;
$dd = @MDAY
$yy = StringRight(@YEAR, 2)
$mm = @MON
$yesterdaydate = _DateAdd('d', -1, _NowCalcDate())
$yesterdaydd = StringRight($yesterdaydate, 2)
$yesterdayMM = StringMid($yesterdaydate, 6, 2)
$yesterdayYY = StringMid($yesterdaydate, 3, 2)
;
;Two days ago (Used for Monday where you need saturday's date)
;
$dateTwoDaysAgo = _DateAdd('d', -2, _NowCalcDate())
$dateTwoDaysAgoDD = StringRight($dateTwoDaysAgo, 2)
$dateTwoDaysAgoMM = StringMid($dateTwoDaysAgo, 6, 2)
$dateTwoDaysAgoYY = StringMid($dateTwoDaysAgo, 3, 2)
;
;Three days ago (Used for Monday where you need last business day of Friday)
;
$dateThreeDaysAgo = _DateAdd('d', -3, _NowCalcDate())
$dateThreeDaysAgoDD = StringRight($dateThreeDaysAgo, 2)
$dateThreeDaysAgoMM = StringMid($dateThreeDaysAgo, 6, 2)
$dateThreeDaysAgoYY = StringMid($dateThreeDaysAgo, 3, 2)
;
$dateyyyymmdd = @YEAR & @MON & @MDAY
$dateprevyyyymmdd = StringLeft($yesterdaydate, 4) & StringMid($yesterdaydate, 6, 2) & StringRight($yesterdaydate, 2)
;
;two weeks ago
;
$twoweeksago = _DateAdd('d', -14, _NowCalcDate())
$twoweeksagoYYYYMMDD = StringLeft($twoweeksago, 4) & StringMid($twoweeksago, 6, 2) & StringRight($twoweeksago, 2)
;
Const $logfilelocation = "G:\AutoIT_Production\Logs\" & _DateToMonth(@MON) & "-" & @YEAR & "\" & $todayMMDDYY & "\Log_" & $todayMMDDYY & ".log"
If Not FileExists($logfilelocation) Then
    FileOpen($logfilelocation, 9)
    FileClose($logfilelocation)
EndIf
;
;get focus info
;
Global $xpfocusxpini = @WindowsDir & "\focusxp.ini"
Global $xpWebServer, $xpOpName, $xpWSDesc
If FileExists($xpfocusxpini) Then
    $xpWebServer = IniRead($xpfocusxpini, "xpwnav", "WebServer", "none")
    $xpOpName = IniRead($xpfocusxpini, "OpName", "WebServer", "none")
    $xpWSDesc = IniRead($xpfocusxpini, "WSDesc", "WebServer", "none")
EndIf
LogAction("****************************************************************************************")
LogAction(StringUpper("***** " & @UserName & " ran reference number: 5250 from " & @ComputerName & " *****"))
LogAction(StringUpper("***** FOCUS XP INFO: Operator:" & $xpOpName & " Workstation Description: " & $xpWSDesc & " *****"))
LogAction(StringUpper("***** Started 5250 Check Import *****"))
LogAction("****************************************************************************************")
Global $5250filename, $5250count, $5250line, $5250tempfilename, $5250OrigFile, $5250PrevDayFile, $5250CurrSeq, $5250PrevSeq, $5250filenameImport, $5250rejectarray
Global $5250rejectarray, $5250RejectFilename, $5250LogFilename, $file
Global $FileList, $upper, $FirstlineArray, $LastlineArray, $newArray[1], $lineArray
$5250filename = "G:\Indexes\hacuchecks.txt"
$5250filenameImport = "G:\Indexes\Index_hacuchecks_import.txt"
$5250tempfilename = "G:\Indexes\Index_hacuchecks_temp.txt"
;$5250OrigFile = "G:\Indexes\backup\Index.txt" ;temp remove - for testing only
$5250OrigFile = "T:\TeChecksIndexBuilder\Archive\Indexes\Index.txt"
$5250BackupFilename = "G:\Indexes\backup\" & _DateToMonth(@MON) & "-" & @YEAR & "\" & $todayMMDD & "_hacuchecks_Index.txt"
$5250RejectFilename = "G:\Indexes\Index_hacuchecks_import.rej"
$5250LogFilename = "G:\Indexes\Index_hacuchecks_import.log"
;
; Make sure the drive mappings are correct.
;
If Not DriveGetDrive("T:") = "\\2003imm\TeChecks" Then
    LogAction("5250 - Had to map T: drive to \\2003imm\TeChecks")
    DriveMapDel("T:")
    Sleep(5000)
    DriveMapAdd("T:", "\\2003imm\TeChecks", 9)
    If @error Then
        MsgBox(4096, "Error", "Drive could not be mapped! Contact IS Manager!")
        LogAction("Drive T: could not be mapped! Contact IS Manager!")
        Exit
    EndIf
    Sleep(5000)
    DriveSetLabel("T:", "IMM_TeChecks")
    LogAction("5250 - T: Drive mapped")
EndIf
If Not DriveGetDrive("G:") = "\\san1\shared\mis" Then
    LogAction("5250 - Had to map G: drive to \\san1\shared\mis")
    DriveMapDel("G:")
    Sleep(5000)
    DriveMapAdd("G:", "\\san1\shared\mis", 9)
    If @error Then
        MsgBox(4096, "Error", "Drive could not be mapped! Contact IS Manager!")
        LogAction("Drive G: could not be mapped! Contact IS Manager!")
        Exit
    EndIf
    Sleep(5000)
    DriveSetLabel("G:", "MIS")
    LogAction("5250 - G: Drive mapped")
EndIf
;
; Delete files as needed
;
ProgressOn("5250 Progress Meter", "Progress", "0 percent")
;
;check temp file
;
If FileExists($5250tempfilename) Then
    $fc = FileDelete($5250tempfilename)
    If @error <> 0 Then
        MsgBox(0, "Error", "Failed to delete file! " & $5250tempfilename & "Please finish manually. Error: " & @error)
        Exit
    EndIf
    LogAction("5250 - Deleted file: " & $5250tempfilename)
EndIf
;;GUICtrlSetData($Progress1, "5")
ProgressSet(5, "5 percent")
If FileExists($5250filename) Then
    $fc = FileDelete($5250filename)
    If @error <> 0 Then
        MsgBox(0, "Error", "Failed to delete file! " & $5250filename & "Please finish manually. Error: " & @error)
        Exit
    EndIf
    LogAction("5250 - Deleted file: " & $5250filename)
EndIf
;;GUICtrlSetData($Progress1, "10")
ProgressSet(10, "10 percent")
If FileExists($5250filenameImport) Then
    $fc = FileDelete($5250filenameImport)
    If @error <> 0 Then
        MsgBox(0, "Error", "Failed to delete file! " & $5250filenameImport & "Please finish manually. Error: " & @error)
        Exit
    EndIf
    LogAction("5250 - Deleted file: " & $5250filenameImport)
EndIf
;
;Copy orig file to a temporary filename
;
FileMove($5250OrigFile, $5250tempfilename, 9)
If @error <> 0 Then
    MsgBox(0, "Error", "Failed to move file! " & $5250OrigFile & " to: " & $5250tempfilename & " Please finish manually. Error: " & @error)
    LogAction("5250 - Failed to move file: " & $5250OrigFile & " to: " & $5250tempfilename & " Please finish manually. Error: " & @error)
    Exit
EndIf
;
;write to log file
;
LogAction("5250 - Moved file: " & $5250OrigFile & " to: " & $5250tempfilename)
;
;wait 4 seconds
;
Sleep(4000)
;;GUICtrlSetData($Progress1, "15")
ProgressSet(15, "15 percent")
;
;backup the orig file
;
FileCopy($5250tempfilename, $5250BackupFilename, 9)
If @error <> 0 Then
    MsgBox(0, "Error", "Failed to copy file! " & $5250tempfilename & " to: " & $5250BackupFilename & " Please finish manually. Error: " & @error)
    LogAction("5250 - Failed to copy file: " & $5250tempfilename & " to: " & $5250BackupFilename & " Please finish manually. Error: " & @error)
    Exit
EndIf
;
;write to log file
;
LogAction("5250 - Copy file: " & $5250tempfilename & " to: " & $5250BackupFilename)
;
;wait 4 seconds
;
Sleep(4000)
;;GUICtrlSetData($Progress1, "20")
ProgressSet(20, "20 percent")
;
; check yesterday's file to make sure we have the check numbers in order
;
If @WDAY = 2 Then
    $5250PrevDayFile = "G:\Indexes\backup\" & _DateToMonth(@MON) & "-" & @YEAR & "\" & $dateThreeDaysAgoMM & $dateThreeDaysAgoDD & "_HACUCHECKS_Index.txt"
Else
    $5250PrevDayFile = "G:\Indexes\backup\" & _DateToMonth(@MON) & "-" & @YEAR & "\" & $yesterdayMM & $yesterdaydd & "_HACUCHECKS_Index.txt"
EndIf
;;GUICtrlSetData($Progress1, "30")
ProgressSet(30, "30 percent")
;
;check if previous days file is available
;
If FileExists($5250PrevDayFile) = True Then
    ;
    ;open both files
    ;
    FileOpen($5250BackupFilename, 0)
    FileOpen($5250PrevDayFile, 0)
    ;
    ;set var for reading first and last lines
    ;
    ;;GUICtrlSetData($Progress1, "35")
    $5250PrevSeq = StringMid(FileReadLine($5250PrevDayFile, -1), 10, 6)
    $5250CurrSeq = StringMid(FileReadLine($5250BackupFilename, 1), 10, 6)
    ;
    ; evaluate the difference between the two values
    ;
    If $5250CurrSeq - $5250PrevSeq <> 1 Then
        MsgBox(48, "Sequence Error!", "Contact the IS Manager! The check sequence is not in order! (Script will still import checks!) Prev: " & $5250PrevSeq & " Today: " & $5250CurrSeq)
    EndIf
    ;
    ;close the files
    ;
    FileClose($5250BackupFilename)
    FileClose($5250PrevDayFile)
    ;;GUICtrlSetData($Progress1, "40")
    ProgressSet(40, "40 percent")
    ;
    ; pause for 5 seconds
    ;
    LogAction("5250 - Check sequence okay prev: " & $5250PrevSeq & " todays: " & $5250CurrSeq)
    Sleep(5000)
Else
    ;
    ;show message box to user about error
    ;
    MsgBox(64, "No Previous Day File", "Previous Day's file is missing. The script can't verify the check sequences. You will have to do this manually.(Script will still import checks!)")
    LogAction("5250 - Previous Day's file is missing. The script can't verify the check sequences.")
EndIf
;
;           GUICtrlSetData($pbar, "50")
;
;
;Delete orig file
;
FileDelete($5250filename)
If @error <> 0 Then
    MsgBox(0, "Error", "Failed to delete file! " & $5250filename & "Please finish manually. Error: " & @error)
    LogAction("5250 - Failed to delete file! " & $5250filename & "Please finish manually. Error: " & @error)
    Exit
EndIf
;
;make corrections in file
;
_ReplaceStringInFile($5250tempfilename, "\\2003IMM\techecks\", "@@T:\", 0, 1)

;
; notify log of status
;
LogAction("5250 - Replaced drive path ")
;;GUICtrlSetData($Progress1, "50")
ProgressSet(50, "50 percent")
;
; pause for 2.5 seconds
;
Sleep(2500)
;
; count the lines in temp file
;
$5250count = _FileCountLines($5250tempfilename)
;MsgBox(0,"Info:","File count lines: " & $5250count)
;
; pause for 2.5 seconds
;
Sleep(2500)
;
; Open files for reading
;
FileOpen($5250tempfilename, 0)
FileOpen($5250filename, 9)
;;GUICtrlSetData($Progress1, "55")
ProgressSet(55, "55 percent")
;
; set variables
;
Global $5250CommaCounter, $5250CommaLocation
;
; cycle the file
;
For $x = 1 To $5250count
    ;
    ;read in each line thru loop
    ;
    $5250line = FileReadLine($5250tempfilename, $x)
    ;MsgBox(0,"Info:","Line  " & $x & " = " & $5250line)
    ; split the line into an array
    ;
    ;
    $5250CommaCounter = StringSplit($5250line, ",")
    ;;GUICtrlSetData($Progress1, "60")
    ProgressSet(60, "60 percent")
    ;_ArrayDisplay($5250CommaCounter)
    ;
    ; test the script to make sure it's a valid line (9 commas)
    ;
    If $5250CommaCounter[0] <> 9 Then
        ;
        ;run select for manipulate data
        ;
        Select
            ;
            ;file has too many comma's lets remove the second one. which is in the name field.
            ;
            Case $5250CommaCounter[0] = 11
                ;
                ;find the comma
                ;
                $5250CommaLocation = StringInStr($5250line, ",", 0, 4)
                ;MsgBox(0, "Info:", "Comma Location: " & $5250CommaLocation)
                ;
                ;correct the line
                ;
                $5250line = StringLeft($5250line, $5250CommaLocation - 1) & StringMid($5250line, $5250CommaLocation + 1, StringLen($5250line) - 1)
                ;MsgBox(0, "Info:", "New Line = " & $5250line)
                ;
                ; write the line
                ;
                FileWriteLine($5250filename, $5250line)
                LogAction("5250 - 11 commas found new line is: " & $5250line)
                ;
                ;file has not enough comma's lets add one. Sometimes happens when there is no name
                ;

            Case $5250CommaCounter[0] = 8
                ;
                ;find comma locaion
                ;
                $5250CommaLocation = StringInStr($5250line, ",", 0, 3)
                ;
                ; fix the line
                ;
                ;MsgBox(0, "Info:", "Comma Location: " & $5250CommaLocation)
                $5250line = StringLeft($5250line, $5250CommaLocation) & "HACU,1234" & StringMid($5250line, $5250CommaLocation + 2, StringLen($5250line) - 1)
                ;
                ; Display to end user new line was done.
                ;
                MsgBox(0, "Info:", "New Line = " & $5250line)
                LogAction("5250 - New Line = " & $5250line)
                ;
                ; write the new line
                ;
                FileWriteLine($5250filename, $5250line)
            Case Else
                MsgBox(0, "Error!:", "This line contains an error:" & @CRLF & $5250line & @CRLF & "please investigate error or contact IS Manager")
                LogAction("5250 - This line contains an error:" & @CRLF & $5250line & @CRLF & "please investigate error or contact IS Manager")
        EndSelect

    Else
        ;
        ;Normal line but we need to check for empty fields
        ;
        $5250CommaLocation = StringInStr($5250line, ",,,", 0, 3)
        ;
        ; normal line write out to new file with no change
        ;
        FileWriteLine($5250filename, $5250line)
    EndIf
Next
LogAction("5250 - File process complete")
;           GUICtrlSetData($pbar, "75")
ProgressSet(70, "70 percent")
;
; pause for 1.5 seconds
;
Sleep(1500)
;
; close the file
;
FileClose($5250filename)
LogAction("5250 - File Closed: " & $5250filename)
;;GUICtrlSetData($Progress1, "70")
ProgressSet(75, "75 percent")
;
; pause for 1.5 seconds
;
Sleep(1500)
;
; close the file
;
FileClose($5250tempfilename)
LogAction("5250 - File Closed: " & $5250tempfilename)
;
; pause for 5 seconds
;
Sleep(5000)
;;GUICtrlSetData($Progress1, "80")
ProgressSet(80, "80 percent")
;
; check for file
;
If FileExists($5250tempfilename) Then
    ;
    ;delete file
    ;
    $fc = FileDelete($5250tempfilename)
    ;
    ; write to log
    ;
    LogAction("5250 - Delete File: " & $5250tempfilename)
EndIf
; pause for 2 seconds
;
Sleep(2000)
;
; copy the file
;
FileCopy($5250filename, $5250filenameImport, 9)
LogAction("5250 - Copied file: " & $5250filename & " to: " & $5250filenameImport)
;
; run the import
;


;
; pause for 3 seconds
;
;Sleep(3000)
;LogAction("5250 - Waited 3 seconds")
;;GUICtrlSetData($Progress1, "90")
;ProgressSet(90, "90 percent")
;LogAction("5250 - Updated progress to 90")
;
; set variables
;
$sDir = "G:\AutoIT_Production\5250"
LogAction("5250 - $sDir=" & $sDir)
$sFile = "5250.bat"
LogAction("5250 - $sFile=" & $sFile)
LogAction("5250 - Set directory for batch file: " & $sDir & "\" & $sFile)
;
; run the import
;
RunWait($sDir & "\" & $sFile, $sDir, @SW_SHOW)
;
;write to log file
;
LogAction("5250 - Running import script: " & $sDir & "\" & $sFile)
;
;lets verify no rejects
;
;
; pause for 5 seconds
;
ProgressSet(92, "92 percent")
LogAction("5250 - Progress set to 92")
Sleep(5000)
LogAction("5250 - Waited 5 seconds")
;
;write log file to auto it log
;
Global $logarray
_FileReadToArray($5250LogFilename, $logarray)
For $x = 1 To $logarray[0]
    LogAction("1750 - Import Log: " & $logarray[$x])
Next
;
;search for rejects
;
LogAction("5250 - Checking for rejects:")
If FileGetSize($5250RejectFilename) <> "0" Then
    ;
    ; tell end user abour reject
    ;
    MsgBox(48, "Rejects found!", "A reject was found that the script could not fix! You will need to correct this! Click ok to view the rejects.")
    LogAction("5250 - Rejects found:")
    ;
    ; set the variables
    ;
    $sDir = "G:\Indexes\"
    $sCommand = "notepad.exe " & $5250RejectFilename
    ;
    ; run the command to display the rejects
    ;
    Run($sCommand, $sDir, @SW_SHOW)
    ;
    ; read rejects into array
    ;
    _FileReadToArray($5250RejectFilename, $5250rejectarray)
    ;
    ; cycle thru array
    ;
    For $x = 1 To $5250rejectarray[0]
        ;
        ;write reject log to regular log
        ;
        LogAction("5250 - " & $5250rejectarray[$x])
    Next
    ;
    ;email reject log to IS Manager
    ;
    $Body = "Reject in 5250 file: " & $5250RejectFilename & " Please review!"
    $AttachFiles = $5250RejectFilename
    _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
Else
    LogAction("5250 - No rejects found")
EndIf
ProgressSet(95, "95 percent")
;
;verify the database for the import
;

If Not _FileReadToArray($5250filenameImport, $FileList) Then
    MsgBox(4096, "Error", " Error reading import file to Array     error:" & @error)
    Exit
EndIf
;_ArrayDisplay($FileList)

$upper = $FileList[0]
;split them into arrays
$FirstlineArray = StringSplit($FileList[1], ",", 0)
$LastlineArray = StringSplit($FileList[$upper], ",", 0)

_SQL_Startup()
_SQL_RegisterErrorHandler()

$newArray[0] = 0
;
ProgressSet(97, "97 percent")
If _SQL_Connect(-1, "192.168.0.18", "EMC", "userx", "passxxxx") = $SQL_ERROR Then
    MsgBox(0 + 16 + 262144, "Error", _SQL_GetErrMsg())
    LogAction("5250 - SQL error: " & _SQL_GetErrMsg())
EndIf
Global $x
Local $aResult, $iRows, $iColumns
For $n = 1 To $upper
    $lineArray = StringSplit($FileList[$n], ",", 0)
    _SQL_GetTable2D(-1, "Select field2,field3,field4,field7 FROM sysop.ae_dt13 where field2=" & $lineArray[2], $aResult, $iRows, $iColumns);
    If @error Then
        ;no qwery returned
        $x = _SQL_GetErrMsg()
        If $x = "Query has no data" Then
            _ArrayAdd($newArray, $FileList[$n] & " - Missing")
            $newArray[0] += 1
        Else
            ; some other SQL error need to notify user and log it
            MsgBox(0, "", $x)
            LogAction($x)
        EndIf
        $missingboolean = True
    Else
        ;qwery returned
        _ArrayAdd($newArray, $FileList[$n] & " - Found")
        $newArray[0] += 1
    EndIf


Next
If $missingboolean = True Then
    ;
    ;send not found to log and display them for user
    ;
    Global $u, $notify
    For $u = 1 To $newArray[0]
        If StringRight($newArray[$u], 7) = "Missing" Then
            $notify = $notify & "Item not imported: " & $newArray[$u] & @CRLF
            LogAction("!!! ERROR !!!!! ERROR !!!!! ERROR !!!!! ERROR !!!!! ERROR !!! - MISSING FROM DATABASE:")
            LogAction("5250 - Item not imported: " & $newArray[$u])
        EndIf
    Next
    ;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Height=500
    If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
    $sInputBoxAnswer = InputBox("Enter comment:", "Please enter a comment on why these items are missing from the import (Review reject log as needed)" & @CRLF & $notify, "", " ", "-1", "500", "-1", "-1")
    Select
        Case @error = 0 ;OK - The string returned is valid
            LogAction("5250 - Comment added: " & $sInputBoxAnswer)
        Case @error = 1 ;The Cancel button was pushed
            LogAction("5250 - No comment was added")
        Case @error = 3 ;The InputBox failed to open
            LogAction("5250 - Error opening input box")
    EndSelect
Else
    LogAction("5250 - No missing items from database.")
EndIf
ProgressSet(100, "100 percent", "Complete")
;
;all done
;
MsgBox(64, "Complete", "5250 import complete")
LogAction("****************************************************************************************")
LogAction(StringUpper("***** Completed 5250 Check Import *****"))
LogAction("****************************************************************************************")
;
; Functions below
;
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 Then $IPPort = 25
    $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail = ""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

Func LogAction($logtext)
    ;log to the screen listbox
    $tTime = _Date_Time_GetLocalTime()
    ;log to the text file
    FileOpen($logfilelocation, 9)
    FileWriteLine($logfilelocation, _Date_Time_SystemTimeToDateTimeStr($tTime) & " - " & $logtext)
    FileClose($logfilelocation)
EndFunc   ;==>LogAction

Error Seciton:

FileCopy($5250filename, $5250filenameImport, 9)
LogAction("5250 - Copied file: " & $5250filename & " to: " & $5250filenameImport)
;
; run the import
;
;
; pause for 3 seconds
;
;Sleep(3000)
;LogAction("5250 - Waited 3 seconds")
;;GUICtrlSetData($Progress1, "90")
;ProgressSet(90, "90 percent")
;LogAction("5250 - Updated progress to 90")
;
; set variables
;
$sDir = "G:\AutoIT_Production\5250"

Log File:

05/07/2010 07:38:19 - ****************************************************************************************

05/07/2010 07:38:19 - ***** ADMINISTRATOR RAN REFERENCE NUMBER: 5250 FROM MISS-VM *****

05/07/2010 07:38:19 - ***** FOCUS XP INFO: OPERATOR:NONE WORKSTATION DESCRIPTION: NONE *****

05/07/2010 07:38:19 - ***** STARTED 5250 CHECK IMPORT *****

05/07/2010 07:38:20 - ****************************************************************************************

05/07/2010 07:38:20 - 5250 - Had to map T: drive to \\2003imm\TeChecks

05/07/2010 07:38:30 - 5250 - T: Drive mapped

05/07/2010 07:38:30 - 5250 - Had to map G: drive to \\san1\shared\mis

05/07/2010 07:38:40 - 5250 - G: Drive mapped

05/07/2010 07:38:40 - 5250 - Deleted file: G:\Indexes\Index_hacuchecks_temp.txt

05/07/2010 07:38:40 - 5250 - Deleted file: G:\Indexes\hacuchecks.txt

05/07/2010 07:38:40 - 5250 - Deleted file: G:\Indexes\Index_hacuchecks_import.txt

05/07/2010 07:38:41 - 5250 - Moved file: T:\TeChecksIndexBuilder\Archive\Indexes\Index.txt to: G:\Indexes\Index_hacuchecks_temp.txt

05/07/2010 07:38:45 - 5250 - Copy file: G:\Indexes\Index_hacuchecks_temp.txt to: G:\Indexes\backup\May-2010\0507_hacuchecks_Index.txt

05/07/2010 07:38:49 - 5250 - Check sequence okay prev: 253307 todays: 253308

05/07/2010 07:38:54 - 5250 - Replaced drive path

05/07/2010 07:39:05 - 5250 - File process complete

05/07/2010 07:39:07 - 5250 - File Closed: G:\Indexes\hacuchecks.txt

05/07/2010 07:39:08 - 5250 - File Closed: G:\Indexes\Index_hacuchecks_temp.txt

05/07/2010 07:39:13 - 5250 - Delete File: G:\Indexes\Index_hacuchecks_temp.txt

05/07/2010 07:39:15 - 5250 - File Closed: G:\Indexes\hacuchecks.txt

05/07/2010 07:39:17 - 5250 - Copied file: G:\Indexes\hacuchecks.txt to: G:\Indexes\Index_hacuchecks_import.txt

post-32114-1273241481088_thumb.jpg

post-32114-1273241584909_thumb.jpg

Edited by FrozenTeeth

Share this post


Link to post
Share on other sites
SKlocke

The only occurence of $doscommand in your script that I can find is when you put it into the RunWait.

Could it be that you pass a String with uninitialized content to RunWait to execute?

I'd add a log message writing the content of the command you want to execute to debug.

Share this post


Link to post
Share on other sites
FrozenTeeth

The only occurence of $doscommand in your script that I can find is when you put it into the RunWait.

Could it be that you pass a String with uninitialized content to RunWait to execute?

I'd add a log message writing the content of the command you want to execute to debug.

I must appologize. I meant to remove that line. I was going to try to runt the copy with the dos xcopy command. I have updated the first post to reflect the true script.

Here is what I was going to try. I can't run it at a whim because it would mess with live data. I run it once a day. My next test is Monday :idea:

Local $doscommand
$doscommand = "xcopy " & $5250filename & " " & $5250filenameImport & " /c /q /y"
LogAction("5250 - Copied file: " & $5250filename & " to: " & $5250filenameImport)

Share this post


Link to post
Share on other sites
evilertoaster

Have you seen/read this article? - http://support.microsoft.com/kb/884069

Share this post


Link to post
Share on other sites
FrozenTeeth

Tried your suggestion and am not getting a 1005 error but a 1000 error. Here is a screen shot from the event log.

Looked it up on eventid.net but seems to be a general error.

post-32114-12732639678119_thumb.jpg

Share this post


Link to post
Share on other sites
evilertoaster

Hum, you sure there's no hardware problems? bad hard drive or NIC maybe?

Are you able to try running the script under a different OS (non-XP)?

Does the .bat script using xcopy work?

Share this post


Link to post
Share on other sites
omikron48

Have you tried checking for file locks?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×