Sign in to follow this  
Followers 0
computergroove

Do Until compare an array and reset an array to all 0's problem.

3 posts in this topic

I have 5 devices on my network and I want to wait until I can ping all of them before I continue with my script. Here is my code snippet:

Global $NumberOfDevices = 5
Global $IPAddress1 = "192.168.1.100"
Global $IPAddress2 = "192.168.1.101"
Global $IPAddress3 = "192.168.1.104"
Global $IPAddress4 = "192.168.1.105"
Global $IPAddress5 = "192.168.1.106"
Global $IPArray[5] = [$IPAddress1, $IPAddress2, $IPAddress3, $IPAddress4, $IPAddress5]
Global $PingRestartArray[5] = [0, 0, 0, 0, 0]

Func PingDevices()
    Do
        For $i = 1 To $NumberOfDevices
            Local $Var = Ping($IPArray[$i], 1000)
            If $Var Then
                $PingRestartArray[$i] = 1
            EndIf
        Next
    Until $PingRestartArray == [1, 1, 1, 1, 1];<-How should this look?
    $PingRestartArray = [0, 0, 0, 0, 0];<-How should this look?
EndFunc

I am getting an errorin the commented lines at the bottom. How do I compare an array at the until line? How do I reset all the values to 0 after Im done?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this (untested):

 

Global $NumberOfDevices = 5
Global $IPAddress1 = "192.168.1.100"
Global $IPAddress2 = "192.168.1.101"
Global $IPAddress3 = "192.168.1.104"
Global $IPAddress4 = "192.168.1.105"
Global $IPAddress5 = "192.168.1.106"
Global $IPArray[5] = [$IPAddress1, $IPAddress2, $IPAddress3, $IPAddress4, $IPAddress5]
Global $z

Func PingDevices()
    Do
        $z = 0
        For $i = 0 To $NumberOfDevices - 1
            If Ping($IPArray[$i], 1000) Then $z += 1
        Next
    Until $z = $NumberOfDevices
EndFunc
 

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Something like this (untested):

Global $aIPAddress[} = ["192.168.1.100", "192.168.1.101", "192.168.1.104", "192.168.1.105". "192.168.1.106"]

Func PingDevices()
    Local $iAdresses = UBound($aIPAddress) - 1 ; Number of addresses to ping
    Local $iPinged = 0 ; Number of successfully pinged adresses
    While 1
        For $i = 0 To $iAdresses
            If $aIPAddress[$i] <> "" Then 
                If Ping($aIPAddress[$i], 1000) <> 0 Then 
                    $aIPAddress[$i] = "" ; All successfully pinged adresses are removed from teh array
                    $iPinged = $iPinged + 1 
                Else
                    $iPinged = $iPinged + 1 
                EndIf
            EndIf
        Next
        If $iPinged = $iAdresses Then Return ; All addresses pinged
    WEnd
EndFun
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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