PsychOfMSE Posted May 7, 2014 Posted May 7, 2014 (edited) So this should be very simple for you guys, but I've been banging my head against the wall for a while now and I'm running out of time getting an example script set up. Basically what i'm doing is using ProgAndy's CSV UDF to parse a CSV with 3 columns and n amount of rows. The structure of the CSV is: Hostname IP AgentType TEST001 192.168.1.1 1 TEST002 192.168.1.2 2 TEST003 192.168.1.3 1 TEST004 192.168.1.4 2 $Data = _ParseCSV('C:\test.csv', ",", '"', 0) So now I have a variable, $Data. What I want to do is create a loop that will go through each row and run a command using data from each column as variables. It's basically going to be a loop to a RunWait for a program that I'll be inserting the data from each column into the command line syntax as a variable, example: ;If Hostname field is populated but IP field is not use the command: RunWait('C:\Example.exe -Hostname="TEST001" -AgentType="1"') ;If IP field is populated but hostname is not, use the command: RunWait('C:\Example.exe -IP="192.168.1.1" -AgentType="1"') ;If both fields are populated default to using the IP address RunWait('C:\Example.exe -IP="192.168.1.1" -AgentType="1"') The CSV could have any amount of rows, maybe up to 2000+ rows, but will always have 3 columns. I'm sure this is an easy solution for you guys, but I'm running out of time and I just can't wrap my head around it. Arrays are one of the last pieces of AutoIT that is truly evading my comprehension. I'm the kind of person that learns best by being shown examples that directly relate to my problem and then tailoring that to fit my solution and then memorybanking it for later use. Thank you all so much! Edited May 7, 2014 by PsychOfMSE
BrewManNH Posted May 7, 2014 Posted May 7, 2014 (edited) Something like this? For $Loop = 0 to Ubound($Data) - 1 If $Data[$Loop][0] <> "" and $Data[$Loop][1] = "" Then ;If Hostname field is populated but IP field is not use the command: RunWait('C:\Example.exe -Hostname=' & $Data[$Loop][0] & ' -AgentType=' & $Data[$Loop][2]) ElseIf $Data[$Loop][1] <> "" Then ;If IP field is populated but hostname is not, use the command: ;If both fields are populated default to using the IP address RunWait('C:\Example.exe -IP=' & $Data[$Loop][1] & ' -AgentType=' & $Data[$Loop][2]) EndIf NextThe array elements used would depend on how the _ParseCSV returns the information Edited May 7, 2014 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
PsychOfMSE Posted May 7, 2014 Author Posted May 7, 2014 Something like this? For $Loop = 0 to Ubound($Data) - 1 If $Data[$Loop][0] <> "" and $Data[$Loop][1] = "" Then ;If Hostname field is populated but IP field is not use the command: RunWait('C:\Example.exe -Hostname=' & $Data[$Loop][0] & ' -AgentType=' & $Data[$Loop][2]) ElseIf $Data[$Loop][1] <> "" Then ;If IP field is populated but hostname is not, use the command: ;If both fields are populated default to using the IP address RunWait('C:\Example.exe -IP=' & $Data[$Loop][1] & ' -AgentType=' & $Data[$Loop][2]) EndIf Next The array elements used would depend on how the _ParseCSV returns the information The UDF describes the return as: ; Return values .: Success - 2D-Array with CSV data (0-based) Being relatively unfamiliar with arrays, your code looks like it should do exactly what I need it to do, and looks to be easy enough to expound upon to add in the additional functionality I want to implement. As long as that snippet will work with the return value of the _ParseCSV function returns, that looks like exactly what I need...and it clarifies a LOT with arrays for me. Thank you so much!
BrewManNH Posted May 8, 2014 Posted May 8, 2014 I don't know the UDF you're using, and you didn't provide a link, but the snippet I posted should be easy enough to modify to fit if it's not correct. 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
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