Jump to content

Recommended Posts

Posted (edited)

I've made a file copy script that will copy a file to a txt file list of hostnames. I have a ping test function built-in to make sure all the hosts are online. It writes the on and offline hosts to an ini file. I'm running into a problem where if I ping the hosts and all are online, but then the user clicks the "Show me Offline" button, it errors out. I have an if statement in the showmeoffline function that should be popping up a message, but it is skipping the @error and going to the third option, which is erroring out because no offline section was made in the ini file. Could someone take a look at the code below and tell me what I have wrong? I've included the ping function, but the problem is in the showoffline function:

Func _TestPing ()
    $txtLoc = GUICtrlRead($TxtFile)
    FileDelete($IniOffline)
    $M = 0;resets online counter
    $N = 0;resets offline counter
    If $txtloc = "" Then
        MsgBox (4096, "", "You have not loaded a text file with hostnames.")
    Else 
        $lines = _FileCountLines($TxtLoc)
        For $i = 1 to $lines
            $pingserver = FileReadLine($txtloc, $i)
            ProgressOn("Pinging hosts", "")
            ProgressSet ($i/$lines*100, "Pinging hosts...")
            $Pingerror = Ping($pingserver, 200) 
            If $PingError Then
                $M += 1
                IniWrite($IniOffline, "Online", $m, $PingServer)
            Else    
                $N += 1
                Iniwrite($IniOffline, "Offline", $n, $Pingserver)
            EndIf
        Next
        ProgressOff ()
        GUICtrlSetData ($online, $M)
        GUICtrlSetData ($offline, $N)
        If $N = 0 Then
            Msgbox (0, "", "All the computers are ready for copy operation.")
        EndIf
    EndIf
EndFunc ;==>TestPing

Func _ShowOffline ()
    $var = IniReadSection($IniOffline, "Offline")
    $offhosts = ""
    If GUICtrlRead($TxtFile) = "" Then
        MsgBox (4096, "", "You have not loaded a text file and pinged it.")     
    ElseIf @error Then 
        MsgBox(4096, "", "You have no offline hosts.")
    Else
        For $i = 1 To $var[0][0]
            $offhosts &= $var[$i][1] & @CRLF
        Next
        MsgBox(4096, "Offline", $offhosts)
    EndIf
EndFunc;==>ShowOffline
Edited by grunewald6
Posted

Maybe something like this

Func _ShowOffline ()
    $var = IniReadSection($IniOffline, "Offline")
    If @error Then 
    MsgBox(4096, "", "You have no offline hosts.")
    Return 
    $offhosts = ""
    If GUICtrlRead($TxtFile) = "" Then
        MsgBox (4096, "", "You have not loaded a text file and pinged it.")     
Else
        For $i = 1 To $var[0][0]
            $offhosts &= $var[$i][1] & @CRLF
        Next
        MsgBox(4096, "Offline", $offhosts)
    EndIf
EndFunc;==>ShowOffline

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Posted

Thanks, Kerros, it worked. Tunnel vision kills me sometimes...

Maybe something like this

Func _ShowOffline ()
    $var = IniReadSection($IniOffline, "Offline")
    If @error Then 
    MsgBox(4096, "", "You have no offline hosts.")
    Return 
    $offhosts = ""
    If GUICtrlRead($TxtFile) = "" Then
        MsgBox (4096, "", "You have not loaded a text file and pinged it.")     
Else
        For $i = 1 To $var[0][0]
            $offhosts &= $var[$i][1] & @CRLF
        Next
        MsgBox(4096, "Offline", $offhosts)
    EndIf
EndFunc;==>ShowOffline

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
×
×
  • Create New...