Jump to content

insert file here


Recommended Posts

i'm trying to make a log of a sort to how much i work. sure, we have those punch card things, but i'd like to make sure they're not rigged.

yes, i'm paranoid. very.

point is, for prettyness purposes, i'm trying to put something like this

@mon.@year working hours are

<insert log file here>

FileRead(log file) obviously failed, or i managed to screw a single line somehow...

either way, it's not working.

$filer=fileread(@scriptdir&"\"&@mon&"."&@year&".txt")
filewrite(@scriptdir&"\Finished logs\"&@mon&"."&@year&".txt", @mon&"."&@year&" Log "&@crlf&@crlf&$filer)

i then tried making an elaborate loop to read each line individually and put it in where i want them. that made my program eat a hefty 30% cpu and run for a while without seemingly doing ANYTHING (5 min and counting)

sutpidly, i deleted the loop so i can't present it, but it was fairly idiotic anyway and didn't show any progress...

now i'm trying to think of anything else, but i'm stumped....

Link to comment
Share on other sites

First of all, when you use FileWrite() it's better to just do it once OR use a use a handle as returned from FileOpen.

Secondly, you didn't post any of the code you are using to sort the lines. It's pretty easy to use a lot of CPU when a loop (assuming you used one) gets screwed up.

Thirdly, I would normally have the results of FileRead() stored as a variable (and potentially as an array) so it can easily be manipulated.

Give us an idea of what and how you are trying to sort and we can probably help you out a bit.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Can you give an example of what exactly you are trying to achieve?

Do you have a file for each month called ex "05.2010.txt": (For May) with hours in it and then calculating something based on that or what?

Don't just say yes.

Maybe just say what your input source is (and what it looks like) and what the output should look like

Link to comment
Share on other sites

@hawky: i don't have files for EACH month, but i made FileOpen() make one if it doesn't exist via flags, and then just calculating the total hours.

my input source is a handmade gui which asks for starting hours (as in, when i started) and offers an ending time (as in, when i stopped) via @hour @min.

the output should look like this

<log file unchanged>
08.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 08
09.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 16

---What i'm trying to acheive---

                   GFSC Working Hours Log
---------------------------------------------------------
08.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 08
09.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 16
---------------------------------------------------------
Total hours: 16
Paid:________
Signature:_______

I managed to get everything except the actual log in there.

when i try to fileread it, i get a blank space, when i try fancy loop #1 the whole things messes up.

currently i'm trying to think of fancy loop #2, but i'm low on inspiration... :idea:

Link to comment
Share on other sites

Oh ok.

If you know where it should be, it should work by reading the log and simply replacing a part of the dest file.

The thing is you say fileread() doesn't work, can you upload an example log file & the destination file?

Maybe there's something in the file? This is basic text and works fine with fileread

<log file unchanged>
08.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 08
09.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 16

---What i'm trying to acheive---

                   GFSC Working Hours Log
---------------------------------------------------------
08.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 08
09.05.2010  |  S: 06:00  |  E: 14:00  |  H: 08  |  TH: 16
---------------------------------------------------------
Total hours: 16
Paid:________
Signature:_______
Edited by hawky358
Link to comment
Share on other sites

If I'm catching your intent correctly, you could use a regular expression to get the TH for each entry and then add them up.

$sStr = FileRead("someFile.txt")
$aHours = StringRegExp($sStr, "(?i)th:\D*(\d+)", 3)
If NOT @Error Then
    $iHours = 0
    For $i = 0 To Ubound($aHours) -1
        $iHours += Number($aHours[$i])
    Next
    MsgBox(0, "Result", "Total Hours = " & $iHours)
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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