# Array problems. plz help

## Recommended Posts

Hi,

I'm hoping that someone could give me a few tips on a problem I have regarding Arrays.

What I'm wanting to do is load a txt file into an Array then search for some text and find the line number of said text. I then need to add an extra 1 to the line number it finds.

So if it finds 5 then = 6, 11 = 12 and so on.

I guess I would then be able to use the variable containg the "line number" to then copy a line from one text file into another.

Example would be

[Test1]

1=jshdjsjsj

2=jshsjdjdhsjdh

[TESTa] <<<< find line number then add 1 to then put the 1=jsjshdfawe "line number" into a variable.

1=jsjshdfawe

2=363632

*** I would rather be able to copy 1=jsjshdfawe into a variable and not worry about adding a 1 to a number.

Otherwise if it were possible then just be able to copy 1=jsjshdfawe into a variable instead for [Testa].

I can normaly work out how to do things but Arrays do confuse me a bit.

I have attached what I have played with so far but can't think how to proceed. I have searched the forums but not been able to work out how to be able to do it. I hope someoneone would be be able to help me.

I have only been able to capture the line of the search string.

#include <Array.au3>

#include <file.au3>

Dim $aRecords _FileReadToArray("c:\in\test.txt",$aRecords)

$sSearch = "[TESTa]" ;<== search text$iIndex = _ArraySearch($aRecords,$sSearch, 0, 0, 0, 1)

If @error Then

If $iIndex = -1 Then Exit EndIf Else MsgBox(0, "Found", '"' &$sSearch & '" was found in the array at position ' & $iIndex & ".") _FileWriteToLine("c:\in\NEWfile.txt", 1, '11 = ' &$iIndex, 1)

EndIf

##### Share on other sites

iiyama,

Welcome to the AutoIt forum.

You need to add 1 to the index you find to get the next line - like this:

#include <Array.au3>
#include <file.au3>

Global $aRecords[4] = [3, "[TESTa]", "1=jsjshdfawe", "2=363632"] ;_FileReadToArray("c:\in\test.txt",$aRecords)

$sSearch = "[TESTa]" ;<== search text$iIndex = _ArraySearch($aRecords,$sSearch);, 0, 0, 0, 1)

If $iIndex = -1 Then Exit Else MsgBox(0, "Found", '"' &$sSearch & '" was found in the array at position ' & $iIndex & ".") MsgBox(0, "WriteLine",$aRecords[$iIndex + 1]) ;_FileWriteToLine("c:\in\NEWfile.txt", 1, '11 = ' &$iIndex, 1)

EndIf

There ia a good tutorial on arrays in the Wiki - you can find it here.

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 on other sites

Hi M23,

I just needed to change a few things to my previous code that I got from yours and it was all good. I should now be able to use it for other things in the future.

It's nice to be able to kinda get my head around Arrays as normaly I try and code any other way to avoid them.

Thanks again.

## Create an account

Register a new account