Sign in to follow this  
Followers 0
robhunter

Two scripts at the same time

4 posts in this topic

Hello,

I have two scripts (well, I have more but the effect is the same with two), they have the same code except for some values that takes from *.INI files.

The problem I have is, sometimes I got the same return values from both scripts, but I know they aren't the same, so I think there's some problem with variables that causes memory to allocate the same values as they has the same variable name...

Here's the code.

#include <date.au3>
#include <ExcelCOM_UDF.au3>
#include <EzMySql.au3>
#include <Array.au3>
#include <file.au3>
#include <IE.au3>
#include <insertar.au3>
#include <Constants.au3>
#include <_FileReadToArray2D.au3>
HotKeySet("{ESC}", "_Quit")
Global $min = @MIN
Global $iSelect = 0
#region ### COGEMOS VARIABLES DEL CONFIG.INI
$uPrincipal = IniRead(@ScriptDir & "\config.ini", "navegaciones", "url", "NotFound")
$uInter = IniRead(@ScriptDir & "\config.ini", "navegaciones", "internet", "NotFound")
$uIntra = IniRead(@ScriptDir & "\config.ini", "navegaciones", "intranet", "NotFound")
$uMov = IniRead(@ScriptDir & "\config.ini", "navegaciones", "movilidad", "NotFound")
$mServidor = IniRead(@ScriptDir & "\config.ini", "MySQL", "servidor", "NotFound")
$mUser = IniRead(@ScriptDir & "\config.ini", "MySQL", "usuario", "NotFound")
$mPasswd = IniRead(@ScriptDir & "\config.ini", "MySQL", "passwd", "NotFound")
$mBBDD = IniRead(@ScriptDir & "\config.ini", "MySQL", "bbdd", "NotFound")
$mPuerto = IniRead(@ScriptDir & "\config.ini", "MySQL", "puerto", "NotFound")
$entidad = IniRead(@ScriptDir & "\config.ini", "basico", "entidad", "NotFound")
$nCheck = IniRead(@ScriptDir & "\config.ini", "basico", "chequeos", "NotFound")

#endregion ### COGEMOS VARIABLES DEL CONFIG.INI
Global $aSections[$nCheck] = ["INTERNET", "INTRANET", "MOVILIDAD"]
Global $aURLs[$nCheck] = [$uInter, $uIntra, $uMov]
Global $aExcel[$nCheck] = ["internet", "intranet", "movilidad"]
If @MIN >= 01 And @MIN <= 15 Then
    $minuto = "15"
ElseIf @MIN >= 16 And @MIN <= 30 Then
    $minuto = "30"
ElseIf @MIN >= 31 And @MIN <= 45 Then
    $minuto = "45"
ElseIf @MIN >= 46 And @MIN <= 59 Or @MIN = 00 Then
    $minuto = "00"
EndIf
$hora = @HOUR & "." & $minuto
While 1
    $sumaOK = 0
    $sumaKO = 0
    $sumaRT = 0
    $s1 = 0
    $s2 = 0
    $s3 = 0
    Local $aFile
    $sSection = $aSections[$iSelect]
    $sURL = $aURLs[$iSelect]
    $sExcel = $aExcel[$iSelect]
    $iSelect += 1
    If $iSelect > UBound($aSections) - 1 Then $iSelect = 0
    $oIE = _IECreate($uPrincipal & $sURL, 0, 0)
    $oTable = _IETableGetCollection($oIE, 1)
    $aTableData = _IETableWriteToArray($oTable, True)
    _IEQuit($oIE)
    $aFilas = UBound($aTableData)
    $tFilas = $aFilas - 1
    If $tFilas > 0 Then
        For $i = 1 To $aFilas - 1
            $dRT = StringReplace($aTableData[$i][5], ",", ".")
            $sumaOK = $sumaOK + $aTableData[$i][1]
            $sumaKO = $sumaKO + $aTableData[$i][2]
            $sumaRT = $sumaRT + $dRT
        Next
        $sumaRTm = $sumaRT / $tFilas
    Else
        $sumaOK = 0
        $sumaKO = 0
        $sumaRTm = 0
    EndIf

    $sFile = FileOpen(@ScriptDir & "\" & $sSection & ".txt", 0)
    $s1 = FileReadLine($sFile, 1)
    $s2 = FileReadLine($sFile, 2)
    $s3 = FileReadLine($sFile, 3)
    FileClose($sFile)
    $sumasOK = $sumaOK + $s1
    $sumasKO = $sumaKO + $s2
    $sumasRT = $sumaRTm + $s3
    _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 1, $sumasOK, 1)
    _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 2, $sumasKO, 1)
    _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 3, $sumasRT, 1)

    Switch $sExcel
        Case "internet"
            $oFile = FileOpen(@ScriptDir & "\" & $sSection & ".txt", 0)
            $OK = FileReadLine($sFile, 1)
            $KO = FileReadLine($sFile, 2)
            $RT = FileReadLine($sFile, 3)
            $decRT = StringReplace($RT, ".", ",")
            FileClose($oFile)

            $oExcel = _ExcelBookOpen(@ScriptDir & "\SSMM_" & $entidad & ".xls", 0)
            _ExcelWriteCell($oExcel, $OK, "A4")
            _ExcelWriteCell($oExcel, $KO, "B4")
            _ExcelWriteCell($oExcel, $decRT, "C4")
            _ExcelWriteCell($oExcel, $hora, "B2")
            _ExcelBookSaveAs($oExcel, @ScriptDir & "\SSMM_" & $entidad & ".xls", "xls", 0, 1)
            _ExcelBookClose($oExcel)
            If @MIN = 00 Or @MIN = 15 Or @MIN = 30 Or @MIN = 45 Then
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 1, 0, 1)
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 2, 0, 1)
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 3, 0, 1)
            EndIf

        Case "intranet"
            $oFile = FileOpen(@ScriptDir & "\" & $sSection & ".txt", 0)
            $OK = FileReadLine($sFile, 1)
            $KO = FileReadLine($sFile, 2)
            $RT = FileReadLine($sFile, 3)
            $decRT = StringReplace($RT, ".", ",")
            FileClose($oFile)

            $oExcel = _ExcelBookOpen(@ScriptDir & "\SSMM_" & $entidad & ".xls", 0)
            _ExcelWriteCell($oExcel, $OK, "F4")
            _ExcelWriteCell($oExcel, $KO, "G4")
            _ExcelWriteCell($oExcel, $decRT, "H4")
            _ExcelBookSaveAs($oExcel, @ScriptDir & "\SSMM_" & $entidad & ".xls", "xls", 0, 1)
            _ExcelBookClose($oExcel)
            If @MIN = 00 Or @MIN = 15 Or @MIN = 30 Or @MIN = 45 Then
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 1, 0, 1)
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 2, 0, 1)
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 3, 0, 1)
            EndIf

        Case "movilidad"
            $oFile = FileOpen(@ScriptDir & "\" & $sSection & ".txt", 0)
            $OK = FileReadLine($sFile, 1)
            $KO = FileReadLine($sFile, 2)
            $RT = FileReadLine($sFile, 3)
            $decRT = StringReplace($RT, ".", ",")
            FileClose($oFile)

            $oExcel = _ExcelBookOpen(@ScriptDir & "\SSMM_" & $entidad & ".xls", 0)
            _ExcelWriteCell($oExcel, $OK, "A22")
            _ExcelWriteCell($oExcel, $KO, "B22")
            _ExcelWriteCell($oExcel, $decRT, "C22")
            _ExcelBookSaveAs($oExcel, @ScriptDir & "\SSMM_" & $entidad & ".xls", "xls", 0, 1)
            _ExcelBookClose($oExcel)
            If @MIN = 00 Or @MIN = 15 Or @MIN = 30 Or @MIN = 45 Then
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 1, 0, 1)
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 2, 0, 1)
                _FileWriteToLine(@ScriptDir & "\" & $sSection & ".txt", 3, 0, 1)
                _insertar()
            Else
                _Quit()
            EndIf

    EndSwitch

WEnd
Func _Quit()
    Exit
EndFunc   ;==>_Quit

Share this post


Link to post
Share on other sites



Sounds more like a bug than a question. You could try making two completely separate scripts. The second script all you have to do is replace every single "$" with "$x" which can be done easily in word or other text processors.

Share this post


Link to post
Share on other sites

The problem is most likely caused by the use of Global variables. Instead you should put your code into a function and declare your variables locally inside that function. I imagine that will solve the problem.

Share this post


Link to post
Share on other sites

I was thinking the same as czardas... the problem should be Global variables, I'll take a look. replacing $ with $x would be useful if there's only two script but as I said, I have more than two :mellow: I just said two because it has problems with two or more.

I'll tell you if I get it to work

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  
Followers 0