Jump to content

How do I make an array for a for loop?


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...