Sign in to follow this  
Followers 0
MaCgyver

Can autoit do it?:

7 posts in this topic

Well I am looking to do the following. In a specific .csv file I want to sort out two specific types of data. One particular column has either XX or YY in the cells. My boss wants me to sort them out, so that we get totals for XX and YY in a report. The .CSV appends data to it through the day and that was done with the autoit and the help of BigDod or was it BidDod? :o . Anyway this would be easy to do within the file, but the users can't have access to manipulate data, so I have to find another method. I am working with the file to see if can put sometype of protection within the worksheet that would allow them to sort and get the totals they are looking for, but not edit the cells. I haven't had to much luck with that idea and my boss probably won't go for it. So before I go work on it somemore I wanted to ask the autoit pros. If autoit could search for all the ROWS that have XX in the first column and import it into something else and the same for all the ROWS that have YY and provide totals for each than my task would be done. I've used autoit on a few other tasks for this project that I am on and it has worked out perfectly. I don't expect Autoit to do everything and if can't do this task I still believe its a powerful software. If it could help me with this task that would just be like have an early Christmas or something.

cliff note: import specific data from a .csv file into some type of grid that cannot be edited by users

Share this post


Link to post
Share on other sites



no reply yet... :o

well i'm looking through autoit help..maybe i can find something.

Share this post


Link to post
Share on other sites

take a look at FileRead() & String*()

will do. thanks!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Assuming your data looks like

XX,100

YY,200

XX,300

YY,500

XX,400

XX,100

Global $xx_count = 0, $yy_count = 0
$file = FileOpen("example.csv", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $data = StringSplit($line, ",")
    
    If $data[1] = "XX" Then
        $xx_count = $xx_count + $data[2]
    Else; I suppose $data[1] = "YY"
        $yy_count = $yy_count + $data[2]
    EndIf
Wend

MsgBox(0x1000,"Output", "XX SUM is " & $xx_count)
MsgBox(0x1000,"Output", "YY SUM is " & $yy_count)

FileClose($file)
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

you made the right assumption. there are more columns, but i will check out what you put together. i really appreciate the help.

it worked like a charm. i will make a few changes in the script to test on the actual file and have the output sent to another file. once i have it done i would like to make a small contribution to this site and something to you,but i dont know if that is allowed on this site. maybe one of the admins can let me know and let me know where to send my contribution to the site. :o

Edited by MaCgyver

Share this post


Link to post
Share on other sites

you made the right assumption. there are more columns, but i will check out what you put together. i really appreciate the help.

it worked like a charm. i will make a few changes in the script to test on the actual file and have the output sent to another file. once i have it done i would like to make a small contribution to this site and something to you,but i dont know if that is allowed on this site. maybe one of the admins can let me know and let me know where to send my contribution to the site. :o

Global $PI_count = 0, $PO_count = 0

$file = FileOpen('GLDAILY.CSV', 0)

$file2 = FileOpen('gldailyPI.csv',1)

$file3 = FileOpen('gldailyPO.csv',1)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to READ file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

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

If $data[2] = "PI" Then

$PI_count = $PI_count + $data[7]

FileWriteLine($file2,$line)

Else; It's assumed that $data[2] = "PO"

$PO_count = $PO_count + $data[7]

FileWriteLine($file3,$line)

EndIf

Wend

;MsgBox(0x1000,"Output", "PI SUM is " & $PI_count)

;MsgBox(0x1000,"Output", "PO SUM is " & $PO_count)

FileClose($file)

FileClose($file2)

FileClose($file3)

;Can I use FileClose($file,file2,$file3) instead?

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