Jump to content

file read


e10
 Share

Recommended Posts

Hi Guys!

I just started autoit and i am sorry i did not discover it earlier! nice, nice!

My question is:

I want to read in this sort of text file:

100,300,200,7200,3600

500,100,1,45,2300

Can I use fileread and tell autoit to read the variable till the , as one variable?

I do not want to use COUNT because COUNT would be changing all the time (I do not want to use 0100 or 0001)

Anyone?

Thanks!!!

e10

Link to comment
Share on other sites

Thanks you all! it works!

I made this out of it.

$file = FileOpen("database.txt", 0)

$chars = FileRead($file, 1)

If @error = -1 Then MsgBox(0, "Error", "Unable to open file.")

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

$Array = StringSplit($line, ",")

plukken()

$doorgaan=MsgBox(0, "", "next line??", 0)

if $doorgaan=0 Then ExitLoop

WEnd

MsgBox(0, "Finished!", "No more data to read")

FileClose($file)

Exit

func plukken()

MsgBox(0, "A=", $Array[1])

MsgBox(0, "B=", $Array[2])

MsgBox(0, "C=", $Array[3])

MsgBox(0, "D=", $Array[4])

MsgBox(0, "T=", $Array[5])

EndFunc

THANKS!

e-10

Link to comment
Share on other sites

e10 ... next time use [ Autoit] [ /Autoit] tags (without the space)

and it will look like

$file = FileOpen("database.txt", 0)

$chars = FileRead($file, 1)
If @error = -1 Then MsgBox(0, "Error", "Unable to open file.")

While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$Array = StringSplit($line, ",")
plukken()
$doorgaan=MsgBox(0, "", "next line??", 0)
if $doorgaan=0 Then ExitLoop
WEnd
MsgBox(0, "Finished!", "No more data to read")
FileClose($file)
Exit

func plukken()
MsgBox(0, "A=", $Array[1])
MsgBox(0, "B=", $Array[2])
MsgBox(0, "C=", $Array[3])
MsgBox(0, "D=", $Array[4])
MsgBox(0, "T=", $Array[5])
EndFunc

Cheers.

Edited by alexmadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

I believe this reads the file a whole lot simpler:

#include <Array.au3>
$text = FileRead("d:\test.txt")
$text = StringReplace($text,Chr(13),"")
$array = StringSplit($text,","&Chr(10))
_ArrayDisplay($array)

But it still excludes your Plukken() function. Since you seem to want to do it line based and all lines contain 5 numbers, you could try:

#include <Array.au3>
$text = FileRead("d:\test.txt")
$text = StringReplace($text, Chr(13), "")
$array = StringSplit($text, "," & Chr(10))
_ArrayDisplay($array, "Full list of read numbers from file")

$amount = $array[0] / 5; the 0th element is the total number of read lines, since you seem to always read lines with 5 numbers this should be ok
Dim $aData[$amount][5]; double-dimmed array that can contain 5 data pieces per element

For $elements = 1 To $amount
    For $elementPieces = 1 To 5
        $aData[$elements-1][$elementPieces-1] = $array[$elements * 5 - 5 + $elementPieces]
    Next
Next
_ArrayDisplay($aData, "Elements read")

/edit: my test file d:\test.txt was:

1,2,3,4,5

12,23,34,45,56

123,234,345,456,567

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

As being already told by SadBunny, this forum rocks due to the sort of people who are here!

Makes a new dummy feel welcome......

Thanks a lot you all.

SadBunny:

I like the new challange you gave me but it will make the script for me only shorter, and not more easy to handle.

I need to compare every variable between the , and then adjust through the right pins on a parallel port positions of stepper motors.

I would like to keep a,b,c,d and t seperate.

(IF YOU DON'T MIND) hahaha :)

O, and ehmm, thanks for a new adiction!

BTW, serial port programming sucks compared to parallel. Parallel is easy!!!

Lots to learn, eager to do.

e-10

Link to comment
Share on other sites

As being already told by SadBunny, this forum rocks due to the sort of people who are here!

Makes a new dummy feel welcome......

Thanks a lot you all.

SadBunny:

I like the new challange you gave me but it will make the script for me only shorter, and not more easy to handle.

I need to compare every variable between the , and then adjust through the right pins on a parallel port positions of stepper motors.

I would like to keep a,b,c,d and t seperate.

(IF YOU DON'T MIND) hahaha ;)

O, and ehmm, thanks for a new adiction!

BTW, serial port programming sucks compared to parallel. Parallel is easy!!!

Lots to learn, eager to do.

e-10

Ok, no problem :) Just thought I'd give you another angle of approach to your situation, codewise. You might want to think about 5 arrays then, if you do need the list (for logging and/or listing purposes perhaps), just $a[x], $b[x], $c[x] etc..

Good luck anyway!

Roses are FF0000, violets are 0000FF... All my base are belong to you.

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