Jump to content
Sign in to follow this  
snowman533

[solved] help with array plz

Recommended Posts

snowman533

hey guys, ive almost got arrays figured out

i want to get all the lines from a txt file that actually have text and display them in a MsgBox

i have no trouble getting the first line to show

how do i show/get the rest?

#Include <Array.au3>
#Include <File.au3>

Dim $aArray[4]
Dim $sDelim
dim $i

$fpath=@desktopdir & "\read to array.txt"

_FileReadToArray($fpath, $aArray)

_ArrayToString($aArray, @TAB, 1, 4)

msgbox(0, "results", $aArray[1])

most of this was acquired from the help file, however i cannot help noticing i am still missing something, tried search and found nothing

cannot find an example that suits my needs

also, how do i get the script to automatically resize the array according to how many lines in the txt file, say if i update the file with a few lines?

thanks in advance ^_^

*edit* attached is the txt file i am working off, currently it is being used as a test, once this is sorted out ill be using it for something else

*edit2* fixed some spelling

read_to_array.txt

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites
Juvigy

^_^

Actually this works great - you just are displaying only one part of the array.

Try this :

msgbox(0, "results", $aArray[0])

msgbox(0, "results", $aArray[1])

msgbox(0, "results", $aArray[2])

msgbox(0, "results", $aArray[3])

msgbox(0, "results", $aArray[4])

Share this post


Link to post
Share on other sites
snowman533

say if i add another few lines to my file, how do i automatically add them? do i have to go in and change the number?

i want to release a certain program that works of a text file but i do not want to change the program every time i update the text file

is there a way to do this


Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites
jinxter

_ArrayDisplay($aArray) will list the values in the array.

ReDim will help you ReDim the Array if needed. The _Array commands will help you aswell.

It's all in the helpfile how to use these commands.


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites
99ojo

say if i add another few lines to my file, how do i automatically add them? do i have to go in and change the number?

i want to release a certain program that works of a text file but i do not want to change the program every time i update the text file

is there a way to do this

Hi,

try this:

#Include <Array.au3>
#Include <File.au3>

Dim $aArray
Dim $sDelim
dim $i

$fpath=@desktopdir & "\read to array.txt"

_FileReadToArray($fpath, $aArray)

_Arraydisplay ($aArray)
Edited by 99ojo

Share this post


Link to post
Share on other sites
99ojo

thankyou 99ojo

#Include <Array.au3>
#Include <File.au3>

Dim $aArray[4]
Dim $sDelim
dim $i

$fpath=@desktopdir & "\read to array.txt"

_FileReadToArray($fpath, $aArray)

For $i = 1 to UBound ($aArray) - 1
   msgbox(0, "results", $aArray[$i])
Next

worked, now to add it to my program, thanks again ^_^

No problem,

i changed the code. Just delete [4] at Line Dim $aArray [4]. You don't have to Dim your array exactly beforehand, if you use _FileReadToArray.

;-))

Stefan

Share this post


Link to post
Share on other sites
snowman533

heres the full code

made a few adjustments ^_^

thanks again, works perfect

now to figure out a way to give u credit in my prog ;)

#Include <Array.au3>
#Include <File.au3>

if FileExists(@scriptdir & "\KILLED.txt") Then
    FileDelete(@scriptdir & "\KILLED.txt")
EndIf

Dim $aArray
$fpath=@scriptdir & "\Baddies.txt"
_FileReadToArray($fpath, $aArray)

Dim $sProcesses = _ArrayToString($aArray)
Dim $aProcesses = StringSplit($sProcesses, '|')
Dim $aProcList = ProcessList()
dim $hLog = FileOpen("KILLED.txt",9)

$ProcessesKilled = 0

For $i = 1 To $aProcesses[0]
      IF ProcessExists($aProcesses[$i]) THEN
          WHILE ProcessExists($aProcesses[$i])
              ProcessClose($aProcesses[$i])
              FileWriteLine($hLog, $aProcesses[$i])
              $Processeskilled += 1
          WEND
      ENDIF
  Next

MsgBox(0,"Results", $ProcessesKilled & " bad programs found, please see: 'KILLED.txt' and 'Process Definitions.txt' in this programs directory" & @lf & @lf & "Current program directory: " & @scriptdir)
FileClose($hLog)

solved

*edit* btw the top If is to make sure that the log is not currently existing, if it is it deletes it, else it will continue from the bottom of the previous scan

Edited by snowman533

Intermediate AutoIt/Autohotkey User

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.