Sign in to follow this  
Followers 0
deef99

Array Confusion

6 posts in this topic

Hello Again,

Thanks to this forum, I've gotten much farther on my code, but I seem to be doing something wrong in the searching of the array now. I know that Column 18 contains the words Heat xx [ex. Heat 23], but it doesn't find it... what am I doing wrong please?

Heatlist.txt:

M;P;Denny;Lennon;;;15;F;A;Ann;Allen;;;4294967295;Chattanooga Dancesport;1;12/03/2010 20:00;Heat 1;American Smooth Single Dance Events;Waltz;Full Silver;B2;2;

M;P;Leon;Selby;;;31;F;A;Diane;Stockton;;;4294967295;Dancemakers;1;12/03/2010 20:00;Heat 1;American Smooth Single Dance Events;Waltz;Full Silver;B2;1;

M;P;Joe;LoCurto;;;35;F;A;Marion;Helman;;;4294967295;Academy Ballroom Atlanta;1;12/03/2010 20:00;Heat 3;American Smooth Single Dance Events;Waltz;Full Silver;B2;3;

M;P;Jorge;Morales;;;36;F;A;Antoinette;Fernando;;;4294967295;Academy Ballroom Atlanta;1;12/03/2010 20:00;Heat 5;American Smooth Single Dance Events;Waltz;Full Silver;B2;4;

M;P;David;Wood;;;32;F;A;Mary Gordon;Taft;;;4294967295;Dancemakers;1;12/03/2010 20:01;Heat 9;American Smooth Single Dance Events;Tango;Preliminary Silver;C2;1;

-------------------------------------------------------------------------------

#include <Array.au3>

; Start array on element 1 of the 2nd dimension

$a_array_one = _MyCSVCustomFunc("C:\cmpmgr\heatlist.txt")

;_ArrayDisplay($a_array_one)

; Start array on element 0 of the 2nd dimension

$a_array_two = _MyCSVCustomFunc("C:\cmpmgr\heatlist.txt")

;_ArrayDisplay($a_array_two, "", 0)

Func _MyCSVCustomFunc($s_csv_file, $s_delimiter = ";", $i_base = 1)

Local $s_read = FileRead($s_csv_file)

Local $a_split_lines = StringSplit(StringStripCR($s_read), @LF)

; Create 2D array

Local $a_ret[$a_split_lines[0] + 1][1]

Local $a_split, $i_add = 0, $i_last_ub = 1

; Populate 2D array

For $i = 1 To $a_split_lines[0]

If $a_split_lines[$i] Then

$i_add += 1

$a_split = StringSplit($a_split_lines[$i], $s_delimiter)

If $i_last_ub < $a_split[0] Then

$i_last_ub = $a_split[0]

Redim $a_ret[$a_split_lines[0] + 1][$a_split[0] + 1]

EndIf

For $n = 1 To $a_split[0]

$a_ret[$i_add][($n - 1) + $i_base] = $a_split[$n]

Next

EndIf

Next

; If there are no matches, set error and return

If $i_add = 0 Then Return SetError(1, 0, 0)

; Reset array with correct dimensions (we only want data, not blank lines)

ReDim $a_ret[$i_add + 1][$i_last_ub + 1]

$a_ret[0][0] = $i_add

Return $a_ret

EndFunc

**** PROBLEM IS DOWN HERE SOMEWHERE ****

global $a_array_two, $iIndex

_ArrayDisplay($a_array_two, "", 0)

$sSearch = InputBox($a_array_two, "Row Number?")

If @error Then Exit

$sColumn = InputBox($a_array_two, "Column to search?")

If @error Then Exit

$sColumn = Int($sColumn)

$iIndex = _ArraySearch($a_array_two, $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

Share this post


Link to post
Share on other sites



deef99,

It might help if you had the correct syntax for the _ArraySearch function - and if you actually asked the function to search for something! :nuke:

At the moment you are using the Row number as the value to search for - so you are very unlikely to find "Heat" or any other string. Furthermore you have missed out the $iForward parameter in the _ArraySearch call, so you are not searching the column you think you are.

Take a look at this slightly modified script - I get the correct answers when I try it: :shifty:

#include <Array.au3>
; Start array on element 1 of the 2nd dimension
$a_array_one = _MyCSVCustomFunc("C:\cmpmgr\heatlist.txt")
;_ArrayDisplay($a_array_one)

; Start array on element 0 of the 2nd dimension
$a_array_two = _MyCSVCustomFunc("C:\cmpmgr\heatlist.txt")
;_ArrayDisplay($a_array_two, "", 0)

Global $a_array_two, $iIndex
_ArrayDisplay($a_array_two, "", 0)

$sSearch = InputBox($a_array_two, "Text to find") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If @error Then Exit

$sColumn = InputBox($a_array_two, "Column to search?")
If @error Then Exit
$sColumn = Int($sColumn)

$iIndex = _ArraySearch($a_array_two, $sSearch, 0, 0, 0, 1, 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

All clear? :x

M23

P.S. When you post code please use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). :P


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

AWESOME!!!!!! Thanks for the super quick response!

One more question please if I may...

Now that I can find the record containing the information, I will want to get the 3 columns after Column 18, and will be saving that data to create a printout on the fly. Can you point me in the direction of what commands I should be looking at to do this?

Appreciate it very much!

Share this post


Link to post
Share on other sites

deef99,

The search will give you the value of the first dimension of the array which holds the required text - and you say that you wish to extract the data in columns 19-21. Thus a small loop should do what you want: :P

$iIndex = _ArraySearch($a_array_two, $sSearch, 0, 0, 0, 1, 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

; Create an empty string
$sData = ""
For $i = 19 To 21
    ; Add the data to the string
    $sData &= $a_array_two[$iIndex][$i] & @CRLF
Next
; And display it
MsgBox(0, "Data", $sData)

I hope that helps. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Perfect!!!! Ok I am moving on....thanks again for the great help!

Share this post


Link to post
Share on other sites

deef99,

Glad I could help. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0