PeterAtkin Posted January 2, 2010 Share Posted January 2, 2010 (edited) I wish to make an array containing the below, but when ever i compile it I get an syntax error, a assume this is because I am mixing strings and numerics, but can not see why thats an issue as it is only an array do I have to somehow declare the variable type within the array? I have found no way to do that so fare what am I missing.. ; $server[x][0] = hostname, $server[x][1] = ip address, Global $serverArr[5][2] = [ _ [scalaserver,10.0.0.1], _ [serverbkuphq,10.0.0.4], _ [carvm1,10.0.0.6], _ [intranetserver,10.0.0.8], _ [server1,10.0.0.9]]Below if the function that i wish use with this array. Func shutdown_servers() For $x = 0 To $s Step 1 $hostname = $serverArr[$x][1] MsgBox(64, "Shutting Down:", "remote system :" & $hostname, 1) $var = Ping($hostname, 250); is the server there? of course it may be blocking with a firewall so you need to check. If $var Then; also possible: If @error = 0 Then ... RunAs($adminuser, $addomain, $adpassword, 0, @ComSpec & " /c " & "shutdown.exe -f -s -m \\" & $hostname & " -t 50 -c ""closing down"" ", @SystemDir, @SW_HIDE) Else MsgBox(16, "Server Status", "An error occured with :" & $hostname & @CRLF & @CRLF & "make sure the server is on or that the firewall allow pings" & @CRLF & "failing that give peter a call XXXX XXXXXXXX", 5) EndIf Next EndFunc ;==>shutdown_serversAny help in this would really be appreciated. Edited November 22, 2014 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
Monolith Posted January 2, 2010 Share Posted January 2, 2010 (edited) You may wan to remove your #number from your post due to ident theft, just a friendly heads up! Edited January 2, 2010 by Monolith Link to comment Share on other sites More sharing options...
PeterAtkin Posted January 2, 2010 Author Share Posted January 2, 2010 (edited) ; $server[x][0] = hostname, $server[x][1] = ip address, Global $serverArr[5][2] = [ _ [scalaserver,10.0.0.1], _ [serverbkuphq,10.0.0.4], _ [carvm1,10.0.0.6], _ [intranetserver,10.0.0.8], _ [server1,10.0.0.9]] Below is the function that i wish use with this array. Looks like I answered my own question as to the arrays, seems after some guess work I came up with this: [code] ; $server[x][0] = hostname, $server[x][1] = ip address, Global $serverArr[5][2] = [ _ [String("scalaserver"), Number("10.0.0.1")], _ [String("serverbkuphq"), Number("10.0.0.4")], _ [String("carvm1"), Number("10.0.0.6")], _ [String("intranetserver"), Number("10.0.0.8")], _ [String("server1"), Number("10.0.0.9")]] However now is seems i need to rewrite this: $hostname = $server[$x][1] as now it comes up as an undeclared variable. Edited January 2, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
ChrisL Posted January 2, 2010 Share Posted January 2, 2010 You need to put each element of your array in speech marks. Global $serverArr[5][2] = [ _ ["scalaserver","10.0.0.1"], _ ["serverbkuphq","10.0.0.4"], _ ["carvm1","10.0.0.6"], _ ["intranetserver","10.0.0.8"], _ ["server1","10.0.0.9"]] [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
PeterAtkin Posted January 2, 2010 Author Share Posted January 2, 2010 (edited) OK all working, seems i had to add the $server as a Global Variable would love to know why? I have attached the working script in the hope that someone else may find this useful to them, and for any advice people can give me for improving my understanding of Autoit. rsd-working_array.au3 Edited January 2, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
ChrisL Posted January 2, 2010 Share Posted January 2, 2010 (edited) OK all working, seems i had to add the $server as a Global Variable would love to know why? I have attached the working script in the hope that someone else may find this rsd-working_array.au3useful to them, and for any advice people can give me for improving my understanding of Autoit. Shouldn't $server actually be $serverArr on line 204? Edit: Yes it should, then you don't need a global $server variable because you don't actually use it anywhere other than that typo, once you change it you then don't need $server at all, also see my post abouve about declaring your array, you used String() but you don't need to Edited January 2, 2010 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
PeterAtkin Posted January 2, 2010 Author Share Posted January 2, 2010 (edited) Thanks got it, New Year should never try and do anything just after new year, as to your post about array I do not see it? Edited January 2, 2010 by PeterAtkin [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
PeterAtkin Posted January 2, 2010 Author Share Posted January 2, 2010 @Monolith where can you see my number becouse I cannot see it anywhere, I hate to be an idiot but then I suppose we all do. [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
ChrisL Posted January 2, 2010 Share Posted January 2, 2010 (edited) Thanks got it, New Year should never try and do anything just after new year, as to your post about array I do not see it? 2 replies above my last post! When you declare your array you do it like this... Global $serverArr[5][2] = [ _ ["scalaserver","10.0.0.1"], _ ["serverbkuphq","10.0.0.4"], _ ["carvm1","10.0.0.6"], _ ["intranetserver","10.0.0.8"], _ ["server1","10.0.0.9"]] Edited January 2, 2010 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
PeterAtkin Posted January 3, 2010 Author Share Posted January 3, 2010 2 replies above my last post! When you declare your array you do it like this... Global $serverArr[5][2] = [ _ ["scalaserver","10.0.0.1"], _ ["serverbkuphq","10.0.0.4"], _ ["carvm1","10.0.0.6"], _ ["intranetserver","10.0.0.8"], _ ["server1","10.0.0.9"]] Thanks done, I finally managed to get the read file into array routine working so got rid of the manual array declaration, your comment really helped me in understanding arrays thank you. Func read_host_file_into_array() ; host file sample (hosts.ini) placed on the desktop If FileExists($hostfile) Then $var = IniReadSection($hostfile, "host_servers") If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $i = 1 To $var[0][0] $serverArr[$i][1] = $var[$i][1] $serverArr[$i][0] = $var[$i][0] ; MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next $sh = UBound($var) - 1; get zize of array just take some leg work out of the for next loops, i'm quit lazy EndIf Else MsgBox(4096, "Host File Error", "The INI file does not exist.") EndIf EndFunc ;==>read_host_file_into_array Now all I have to do is work out had to dynamically resize the array as currently i declare the array as Global $serverArr[99][2] which seems very messy or at the very least wasteful. [topic='115020'] AD Domain Logon Script[/topic] Link to comment Share on other sites More sharing options...
ChrisL Posted January 3, 2010 Share Posted January 3, 2010 (edited) Now all I have to do is work out had to dynamically resize the array as currently i declare the array as Global $serverArr[99][2] which seems very messy or at the very least wasteful. Something like this... Global $$serverArr[1][2];Up at the top of the script where it usually is Func read_host_file_into_array() ; host file sample (hosts.ini) placed on the desktop If FileExists($hostfile) Then $var = IniReadSection($hostfile, "host_servers") If @error Then MsgBox(4096, "Error", "Unable to read section.") Else Redim $serverArr[$var[0][0]+1][2] For $i = 1 To $var[0][0] $serverArr[$i][1] = $var[$i][1] $serverArr[$i][0] = $var[$i][0] ; MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next $sh = UBound($var) - 1; get zize of array just take some leg work out of the for next loops, i'm quit lazy EndIf Else MsgBox(4096, "Host File Error", "The INI file does not exist.") EndIf EndFunc ;==>read_host_file_into_array Edited January 3, 2010 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now