Jump to content

Arraysearch column 0, return value from column 1


Recommended Posts

I have a CSV file which i am putting into a 2D array, for the purpose of this we'll say the 2 columns are "ID" and "NAME"

What I need todo is search the array for a variable (a variable I read from an ini file on the local machine) which is in column 0 but i want to return the value in string in column 1 for that row, ie: 

ID, NAME

01, AAAA

02, BBBB

03, CCCC

 

So if i search in the array for "02" i want it to return the string "BBBB" so i can use this as a variable later on.

I'm using the CSVSplit.au3 from czardas to get my csv into a 2D array which is working perfectly.

I have tried using the _ArraySearch in Combo with _ArrayToString but the output i'm getting is "02, BBBB" instead of just "BBBB" from my example above.

Any help on how todo this would be greatly appreciated, and apologies if this has already been covered, i did look though the forum first but couldn't find a solution. 

Link to comment
Share on other sites

Why not use the INI* functions for this if it's an .ini file?

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 Gude
How 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

Link to comment
Share on other sites

Thanks for your reply.

The ini file on the local machine only has the "ID" in it, not the name, so i have a CSV which matches the ID to the name which i will include within my final exe, so i need to reference the ID pulled out of the ini file against my csv to get the correct name. 

 

Link to comment
Share on other sites

In that case, don't use _ArrayToString, just reference the array's [1] element to get just the second column's text.

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 Gude
How 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

Link to comment
Share on other sites

@subz I could have posted working code, but chose to point the user in the direction they needed so they could learn to use AutoIt.

I'd refer you to my signature, specifically the second line in red as to why.

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 Gude
How 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

Link to comment
Share on other sites

@BrewManNH Actually read your previous post incorrectly, I thought you had written $aArray[1] so was going to just clarify that it was $aArray[_ArraySearch][1] but then thought it wouldn't make sense so just wrote out the function for clarity.

Apologies for that.

Link to comment
Share on other sites

  • 4 years later...

I have exact same  question, but I have a lot of columns: players2.txt and I have ID list: chars.txt

I need to search for these IDs in column 'playerid' of players2.txt table and return 2 values for each id: from 'firstnameid' and 'lastnameid' columns. Searched online but lost tbh Only found this discussion which is very close to the topic.

Please help me

players2.txt

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...