Jump to content
BatMan22

Random 0 writted to end of file?

Recommended Posts

BatMan22

For some reason there is a random 0 written to the end of my file with my coding.. and I don't know why.. I think I turned off all the counters... so I don't know why it's doing it.. help? :)

Func LoadPrepBatchOnly()

    _FileReadToArray(@ScriptDir & "\IC1testcodes.txt", $testcodeIC1, @CRLF)
    _FileReadToArray(@ScriptDir & "\IC2testcodes.txt", $testcodeIC2, @CRLF)
    _FileReadToArray(@ScriptDir & "\IC3testcodes.txt", $testcodeIC3, @CRLF)
    _FileReadToArray(@ScriptDir & "\IC5testcodes.txt", $testcodeIC5, @CRLF)

    MouseClick("primary", 419, 43)
    Sleep(50)
    MouseClick("primary", 104, 182)
    Sleep(200)
    Send("^c")
    $tcfromprepbatch = ClipGet()
    If $tcfromprepbatch = "PR300.1_W" Then $tcfromprepbatch = "300.1_W"
    If $tcfromprepbatch = "PR300.0_S" Then $tcfromprepbatch = "300.0_S"
    If $tcfromprepbatch = "PR300.1SPE_W" Then $tcfromprepbatch = "300.1SPE_W"
    If $tcfromprepbatch = "PR300.1_WIPE" Then $tcfromprepbatch = "PR300.1_WI"
    If $tcfromprepbatch = "PR314_W" Then $tcfromprepbatch = "314_W"
    If $tcfromprepbatch = "PRSULFITE300_W" Then $tcfromprepbatch = "300.1_SULFITE_W"
    If $tcfromprepbatch = "PR218.6_W" Then $tcfromprepbatch = "218.6_W"
    If $tcfromprepbatch = "PR218.6_DW" Then $tcfromprepbatch = "218.6_DW"



    Local $found = _ArraySearch($testcodeIC1, $tcfromprepbatch)
    Local $testnotfound = "poop"
    If $found <> -1 Then
        $WhichMachine = "1"
        MsgBox(0, 0, "Machine Is: " & $WhichMachine)
        $testnotfound = "notpoop"
;~      SortAndCompareToExisting($WhichMachine)
    EndIf

    Local $found = _ArraySearch($testcodeIC2, $tcfromprepbatch)
    If $found <> -1 Then
        $WhichMachine = "2"
        MsgBox(0, 0, "Machine Is: " & $WhichMachine)
        $testnotfound = "notpoop"
;~      SortAndCompareToExisting($WhichMachine)
    EndIf

    Local $found = _ArraySearch($testcodeIC3, $tcfromprepbatch)
    If $found <> -1 Then
        $WhichMachine = "3"
        MsgBox(0, 0, "Machine Is: " & $WhichMachine)
        $testnotfound = "notpoop"
;~      SortAndCompareToExisting($WhichMachine)
    EndIf

    If $testnotfound = "poop" Then
        MsgBox(0, 0, "TestCodeUnknown! and the TC is: " & $tcfromprepbatch)
        _ArrayDisplay($testcodeIC3)
        Exit
    EndIf


    Send("{Enter}")
    MouseClick("primary", 180, 298)
    Sleep(200)
    Send("^c")
    $text = ClipGet()
    $textsplitbefore = StringSplit($text, @CRLF, 2)
    $textsplit = RemoveEmptyArrayElements($textsplitbefore)

    $sFileName = "\left.txt"
    For $i = 0 To UBound($textsplit) - 1
        If $textsplit[$i] <> "" Or " " Then
            FileWrite($sFileName, $textsplit[$i] & " " & $tcfromprepbatch & @CRLF)
        EndIf
    Next

    FileClose($sFileName)


EndFunc   ;==>LoadPrepBatchOnly

Func RemoveEmptyArrayElements($textsplitbefore)
    Local $_Item
    For $_Element In $textsplitbefore
        If $_Element = '' Then
            _ArrayDelete($textsplitbefore, $_Item)
        Else
            $_Item += 1
        EndIf
    Next
    Return ($textsplitbefore)
EndFunc   ;==>RemoveEmptyArrayElements

Func SortAndCompareToExisting($WhichMachine)

    $sFileName = "\left.txt"
    $sFileName2 = "\ic3.txt"
    FindAndReplace("&SampID", "", $sFileName)
    FindAndReplace("&SampID", "", $sFileName2)
    FindAndReplace("PR300.1_W", "300.1_W", $sFileName)
    FindAndReplace("PR300.0_S", "300.0_S", $sFileName)
    FindAndReplace("PR300.1SPE_W", "300.1SPE_W", $sFileName)
    FindAndReplace("PR300.1_WIPE", "PR300.1_WI", $sFileName)

    $Whattowrite = StringRegExpReplace(FileRead($sFileName), "(?m)/*$", "") ; Remove Empty Lines
    FileOpen($sFileName, 2)
    FileWrite($sFileName, $Whattowrite)
    FileClose($sFileName)

    $Whattowrite = StringRegExpReplace(FileRead($sFileName2), "(?m)/*$", "") ; Remove Empty Lines
    FileOpen($sFileName2, 2)
    FileWrite($sFileName2, $Whattowrite)
    FileClose($sFileName2)

    Local $aFile, $aArray, $aFile2, $aArray2
    _FileReadToArray($sFileName, $aFile, $FRTA_NOCOUNT)
    _FileReadToArray($sFileName2, $aFile2, $FRTA_NOCOUNT)

;~  _ArrayDisplay($aFile)
    _ArrayAdd($aFile, $aFile2)

    _ArraySort($aFile, 1, 1)
    $aArray = _ArrayUnique($aFile, 0, 0, 0, $FRTA_NOCOUNT)
    _ArrayDelete($aArray, 0)
;~  _ArrayDisplay($aArray)
    _FileWriteFromArray($sFileName, $aArray)

EndFunc   ;==>SortAndCompareToExisting



Func CheckForDupsOnlyLookingAtSampleID()
    $sFileName = "\left.txt"
    Local $sText = FileRead($sFileName)
    $sText = StringRegExpReplace($sText, "(?m)^(\w{7}-\w{4} \w{3}\.\w{3})(\s<.*\R)(\g1\R?)", "$1$2")
    ConsoleWrite($sText & @LF)
    FileOpen($sFileName, 2)
    FileWrite($sFileName, $sText)
    FindAndReplace("<", "", $sFileName) ; Change First Two Patterns to go go!
    FindAndReplace(">", "", $sFileName) ; Change First Two Patterns to go go!
    FindAndReplace("; ", "/", $sFileName) ; Change First Two Patterns to go go!
    FindAndReplace("NO3/NO3_1/", "NO3/", $sFileName) ; Change First Two Patterns to go go!
    FindAndReplace("NO2/NO2_1/", "NO2/", $sFileName) ; Change First Two Patterns to go go!
    $Whattowrite = StringRegExpReplace(FileRead($sFileName), "(?m)/*$", "") ; Remove Empty Lines
    FileOpen($sFileName, 2)
    FileWrite($sFileName, $Whattowrite)
    FileClose($sFileName)

EndFunc   ;==>CheckForDupsOnlyLookingAtSampleID

 

Share this post


Link to post
Share on other sites
Deye

"We cannot test with what you have posted" > but: 

maybe it has to do with  $iBase value in _FileWriteFromArray
 

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.