tes5884 Posted October 24, 2012 Posted October 24, 2012 The script is looping through a csv file with old pc names. It's then supposed to rename the pc's base on the service tag. It seems to broken at the section where it loops through the array. What am I doing wrong? Thanks!! #include <Constants.au3> #include <Array.au3> #include <CSV.au3> $pid = Run("wmic bios get serialnumber", "", "", $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($pid) $std = StdoutRead($pid) $tag = StringRight(StringStripWS($std, 8), 7) Local $dpt = "DPT" Local $nPcName = $dpt & "-" & $tag $oPcName = _ParseCSV("test.csv") For $i = 0 To UBound($oPcName) Run(@ComSpec & " /k netdom renamecomputer " & $oPcName[$i] & " /NewName:" & $nPcName & " /Force") Next www.tspitz.com
BrewManNH Posted October 24, 2012 Posted October 24, 2012 I'm assuming when you say broken it means you're getting an array subscript error? If so, use For $i = 0 to Ubound($oPCName) - 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
tes5884 Posted October 24, 2012 Author Posted October 24, 2012 Tried that, still got error below. ServiceTag.au3 (19) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Run(@ComSpec & " /k netdom renamecomputer " & $oPcName[$i] & " /NewName:" & $nPcName & " /Force") Run(@ComSpec & " /k netdom renamecomputer " & ^ ERROR The CSV file contains the following values;tzvi-pc test-pc Thanks! www.tspitz.com
jdelaney Posted October 24, 2012 Posted October 24, 2012 Let me try this post again... Do an _arraydisplay after the following line $oPcName = _ParseCSV("test.csv") send us back the output IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
tes5884 Posted October 24, 2012 Author Posted October 24, 2012 the array seems to be fine, see attached. Thanks! www.tspitz.com
Developers Jos Posted October 24, 2012 Developers Posted October 24, 2012 change this line: For $i = 0 To UBound($oPcName) -1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
tes5884 Posted October 24, 2012 Author Posted October 24, 2012 change this line:For $i = 0 To UBound($oPcName) -1Already did that per BrewManNH www.tspitz.com
Developers Jos Posted October 24, 2012 Developers Posted October 24, 2012 Well, With the provided info that should fix it since your array only has 0 & 1 so shown in the arraydisplay. Post the latest version of your script with the arraydisplay before the ForNext loop so we can see what you are testing with. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
BrewManNH Posted October 24, 2012 Posted October 24, 2012 (edited) Add this after the line "For $i = 0 To UBound($oPcName) - 1"ConsoleWrite("$i = " & $i & @CRLF)Run your script from Scite and report the output from the console window at the bottom of the scite screen. Edited October 24, 2012 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
tes5884 Posted October 24, 2012 Author Posted October 24, 2012 Add this after the line "For $i = 0 To UBound($oPcName) - 1" ConsoleWrite("$i = " & $i & @CRLF) Run your script from Scite and report the output from the console window at the bottom of the scite screen. That worked! $i = 0 $i = 1 Now why am I getting an error when I try to get the output of $oPcName[$i] www.tspitz.com
Skruge Posted October 24, 2012 Posted October 24, 2012 (edited) You have a 2-dimensional array, so you have to reference the elements differently. UBound($oPcName) returns 2 because the array is 2-dimensional. (Not the row count, as you were expecting) UBound($oPcName,1) also returns 2 because you have two lines in the CSV file. Try this:For $i = 0 To UBound($oPcName,1) -1 Run(@ComSpec & " /k netdom renamecomputer " & $oPcName[$i][0] & " /NewName:" & $nPcName & " /Force") Next Edit: Missed the -1 Edited October 24, 2012 by Skruge tes5884 1 [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
tes5884 Posted October 24, 2012 Author Posted October 24, 2012 This is the exact and entire script at this time. #include <Constants.au3> #include <Array.au3> #include <CSV.au3> $pid = Run("wmic bios get serialnumber", "", "", $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($pid) $std = StdoutRead($pid) $tag = StringRight(StringStripWS($std, 8), 7) Local $dpt = "DPT" Local $nPcName = $dpt & "-" & $tag $oPcName = _ParseCSV("test.csv") _ArrayDisplay($oPcName) For $i = 0 To UBound($oPcName) -1 ConsoleWrite("$i = " & $i & @CRLF) Run(@ComSpec & " /k netdom renamecomputer " & $oPcName[$i] & " /NewName:" & $nPcName & " /Force") Next www.tspitz.com
tes5884 Posted October 24, 2012 Author Posted October 24, 2012 (edited) @Skruge it worked! Thank you all for helping! This is the working edition if anyone else has the same problem.. #include <Constants.au3> #include <Array.au3> #include <CSV.au3> $pid = Run("wmic bios get serialnumber", "", "", $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($pid) $std = StdoutRead($pid) $tag = StringRight(StringStripWS($std, 8), 7) Local $dpt = "DPT" Local $nPcName = $dpt & "-" & $tag $oPcName = _ParseCSV("test.csv") _ArrayDisplay($oPcName) For $i = 0 To UBound($oPcName, 1) ConsoleWrite("$i = " & $i & @CRLF) Run(@ComSpec & " /k netdom renamecomputer " & $oPcName[$i][0] & " /NewName:" & $nPcName & " /Force") Next Edited October 24, 2012 by tes5884 www.tspitz.com
Mechaflash Posted October 24, 2012 Posted October 24, 2012 The wicked two-headed array strikes again... Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”
jdelaney Posted October 24, 2012 Posted October 24, 2012 (edited) figured as much (mutli dim array, that is) Edited October 24, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
BrewManNH Posted October 24, 2012 Posted October 24, 2012 I missed the Col1 in the array display, good catch. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Skruge Posted October 24, 2012 Posted October 24, 2012 This is the working edition if has the same problem..I'm not sure from your phrasing if you're still having issues, but the code you posted is missing the -1 after UBound. (I edited my post but it looks like you got the original)If you still need help, let us know.Cheers! [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
tes5884 Posted October 24, 2012 Author Posted October 24, 2012 I'm not sure from your phrasing if you're still having issues, but the code you posted is missing the -1 after UBound. (I edited my post but it looks like you got the original)If you still need help, let us know.Cheers!Fixed. It works perfectly thanks..This is the working edition if anyone else has the same problem.. www.tspitz.com
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