Jump to content
Sign in to follow this  
computergroove

How do I make an array for a for loop?

Recommended Posts

computergroove

Sometimes I have 2 IP addresses, Sometimes 3, Sometimes 4 etc. The IP Addresses are not sequential. I want to make a for loop for each IP Address. Right now I just do it the long way without an array.

Func StartVNC()
    Local $Number = 3;Number of IP Addresses
    Local $IP1 = "192.168.1.104", $IP2 = "192.168.1.108", $IP3 = "192.168.1.138"
    For 1 To $Number
        ;Do Something with the IP Address
    Next

If I were to add the ip addresses in an array then I can better see how this would make logical sense. Any help?


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
ricky

Hello,

and like that :

Func StartVNC()
    Local $a_IP[4] = [3,"192.168.1.104","192.168.1.108","192.168.1.138"]
  
    For $i = 1 To Ubound($a_IP) -1
        ;Do Something with the IP Address
    Next

And if you need, you increase the size of the array.

Share this post


Link to post
Share on other sites
Danyfirex

could do something like this:

Local $aArray[3]=["192.168.1.104","192.168.1.108","192.168.1.138"]

For $sIP in $aArray
    ConsoleWrite($sIP & @CRLF)
Next

Saludos

Share this post


Link to post
Share on other sites
JLogan3o13

I believe the question that should be asked is when do you know how many IP addresses you will have? Do you know at the beginning of the script (which would allow you to use something like ricky03 pointed out). Or is it going to be given to you through the script as feedback of some sort. Something like this?

 

Ex: I know one IP, but there may be more...

#include <Array.au3>
#include <MsgboxConstants.au3>

Local $ipArray[1] = ["192.168.1.104"]

While 1
    $ask = InputBox("Please enter an IP address", "")
        _ArrayAdd($ipArray, $ask)
    $confirm = MsgBox($MB_YESNO, "IP Array Example", "Would you like to add another?")
        If $confirm = $IDNO Then ExitLoop
WEnd


_ArrayDisplay($ipArray)
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

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  

×