anixon Posted February 16, 2009 Share Posted February 16, 2009 (edited) I have a text file as per the following example which I want to read into a array display and search routine. The following code as written does not work as it fails to read the data assigned to $string. CODE#include <File.au3> #include <String.au3> #include <Array.au3> ;Single line contents of data.txt ; ;"Anyone","123","anyone@anywhere.org","65432","99","112" Global $string = @ScriptDir & "\data.txt" Local $avArray[1][6] = [[$string]] _ArrayDisplay($avArray, "$avArray") $sSearch = InputBox("_ArraySearch() demo", "String to find?") If @error Then Exit $sColumn = InputBox("_ArraySearch() demo", "Column to search?") If @error Then Exit $sColumn = Int($sColumn) $iIndex = _ArraySearch($avArray, $sSearch, 0, 0, 0, 1, $sColumn) If @error Then MsgBox(0, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.') Else MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.') EndIf Assistance is always appreciated. Ant.. Edited February 16, 2009 by anixon Link to comment Share on other sites More sharing options...
Authenticity Posted February 16, 2009 Share Posted February 16, 2009 Assigning a path to a variable doesn't open the file. First read the whole file using FileRead of _FileReadToArray and then parse the file. Also, you don't need to declare an array variable. Just declare a regular variable and the function will assign an array to it. Link to comment Share on other sites More sharing options...
martin Posted February 16, 2009 Share Posted February 16, 2009 I have a text file as per the following example which I want to read into a array display and search routine. The following code as written does not work as it fails to read the data assigned to $string. CODE#include <File.au3> #include <String.au3> #include <Array.au3> ;Single line contents of data.txt ; ;"Anyone","123","anyone@anywhere.org","65432","99","112" Global $string = @ScriptDir & "\data.txt" Local $avArray[1][6] = [[$string]] _ArrayDisplay($avArray, "$avArray") $sSearch = InputBox("_ArraySearch() demo", "String to find?") If @error Then Exit $sColumn = InputBox("_ArraySearch() demo", "Column to search?") If @error Then Exit $sColumn = Int($sColumn) $iIndex = _ArraySearch($avArray, $sSearch, 0, 0, 0, 1, $sColumn) If @error Then MsgBox(0, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.') Else MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.') EndIf Assistance is always appreciated. Ant.. Perhaps you are forgetting that indexes start at 0. #include <File.au3> #include <String.au3> #include <Array.au3> ;Single line contents of data.txt ; ;"Anyone","123","anyone@anywhere.org","65432","99","112" ;Global $string = @ScriptDir & "\data.txt" Local $avArray[6] = ["one1","two2","three3","four4","five5","six6"];[[$string]] _ArrayDisplay($avArray, "$avArray") $sSearch = InputBox("_ArraySearch() demo", "String to find?") If @error Then Exit $sColumn = InputBox("_ArraySearch() demo", "Column to search?") If @error Then Exit $sColumn = Int($sColumn) $iIndex = _ArraySearch($avArray, $sSearch, 0, 0, 0, 1, $sColumn-1) + 1 If @error Then MsgBox(0, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.') Else MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.') EndIf Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
anixon Posted February 17, 2009 Author Share Posted February 17, 2009 Assigning a path to a variable doesn't open the file.First read the whole file using FileRead of _FileReadToArray and then parse the file. Also, you don't need to declare an array variable. Just declare a regular variable and the function will assign an array to it.I must be a bit dim today cause I have been unable to make it work. If it is not to much trouble can you give me an example using my data file and code? Ant.. Link to comment Share on other sites More sharing options...
anixon Posted February 17, 2009 Author Share Posted February 17, 2009 Perhaps you are forgetting that indexes start at 0. #include <File.au3> #include <String.au3> #include <Array.au3> ;Single line contents of data.txt ; ;"Anyone","123","anyone@anywhere.org","65432","99","112" ;Global $string = @ScriptDir & "\data.txt" Local $avArray[6] = ["one1","two2","three3","four4","five5","six6"];[[$string]] _ArrayDisplay($avArray, "$avArray") $sSearch = InputBox("_ArraySearch() demo", "String to find?") If @error Then Exit $sColumn = InputBox("_ArraySearch() demo", "Column to search?") If @error Then Exit $sColumn = Int($sColumn) $iIndex = _ArraySearch($avArray, $sSearch, 0, 0, 0, 1, $sColumn-1) + 1 If @error Then MsgBox(0, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.') Else MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.') EndIf Thanks for the response however the value of Row[1] in Column [0] should be Anyone [data in the data.txt file] then Row[2] in Column[0] would be 123 Ant.. 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