Jump to content
Sign in to follow this  
rawkhopper

FileWrite 3794 lines limit?

Recommended Posts

Hello everybody,

I have a script that I want to monitor some values over time.  I thought this was a simple task, even for me, so I whipped out a script.  The problem I have is that it seems to stop after a while.  I use the script to write these values every 10 seconds to a text file so that I can later import the file into excel.

 

The first time I got an error message but I didn't write it down (it was not one of my error messages I put in the script) I just assumed that someone messed with the computer it was running on and that caused an error.  The second time I ran the file I did not see an error but I did see something peculiar.  Both files had exactly 3794 lines.  Am I doing something wrong or is this a limitation that I ran into? Or is this just a coincidence?

 

Anyway if you see something wrong with my script please let me know.  The script takes a long time to run and I do not always have access to the tool this runs on to test it out.  So some expert eyes would be greatly appreciated!

 

 

EDIT: I just tried to run the script with a dummy GUI to take info from and I got this error ("C:\Program Files (x86)\AutoIt3\Include\Date.au3" (1220) : ==> Recursion level has been exceeded - AutoIt will quit to prevent stack overflow.:)

I shortened the time so that I could get this error and it still ended up with 3794 lines looks like I must be doing something wrong with Date.au3?

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Date.au3>

CreateFile()

Func CreateFile()
   Global $FileName = @MyDocumentsDir & "\Current" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt"

    ; Create a file to write data to.
   If Not FileWrite($FileName, "Time" & "," & " " & "AccV" & "," & " " & "Emission" & "," & " " & "SIP-1" & "," & " " & "SIP-2" & "," & " " & "Spec" & "," & " " & "Probe Current" & @CRLF) Then
      MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the file.")
      Return False
   EndIf

   Global $hFileOpen = FileOpen($FileName, $FO_APPEND)

   If $hFileOpen = -1 Then
      MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
      Return False
   EndIf

   Current()


    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

EndFunc

Func Current()
   Local $Current = ControlGetText ( "Window", "", 1103 )
   Local $AccV = ControlGetText ( "Window", "", 1001 )
   Local $Emiss = ControlGetText ( "Window", "", 1912 )
   Local $Sip1 = ControlGetText ( "Window", "", 1388 )
   Local $Sip2 = ControlGetText ( "Window", "", 1390 )
   Local $Spec = ControlGetText ( "Window", "", 1312 )

   FileWrite( $hFileOpen, _NowTime() & "," & " " & $AccV & "," & " " & $Emiss & "," & " " & $Sip1 & "," & " " & $Sip2 & "," & " " & $Spec & "," & " " &  $Current & @CRLF )
   Sleep (10000)
   Current ()
EndFunc

 

Edited by rawkhopper

Share this post


Link to post
Share on other sites

Thats no limit of filewrite, but recursion:

Global $Test_Recursion_Limit = 0
Test_Recursion_Limit()

Func Test_Recursion_Limit()
    $Test_Recursion_Limit += 1
    ConsoleWrite($Test_Recursion_Limit & @crlf)
    Test_Recursion_Limit()
EndFunc

 

Share this post


Link to post
Share on other sites

You are calling function Current from within function Current. That's why you reach the recursion limit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites
Just now, water said:

You are calling function Current from within function Current. That's why you reach the recursion limit.

Hmm, how might I do this then?  Should I call a different function that then calls current again?

Share this post


Link to post
Share on other sites

Oh duh

Sometimes I am an idiot...

I just turned the stuff inside Current() to be a While loop and everything seems ok

Thanks for pointing me in the right direction!!!

Share this post


Link to post
Share on other sites
Func Current()
    While True
        Local $Current = ControlGetText("Window", "", 1103)
        Local $AccV = ControlGetText("Window", "", 1001)
        Local $Emiss = ControlGetText("Window", "", 1912)
        Local $Sip1 = ControlGetText("Window", "", 1388)
        Local $Sip2 = ControlGetText("Window", "", 1390)
        Local $Spec = ControlGetText("Window", "", 1312)

        FileWrite($hFileOpen, _NowTime() & "," & " " & $AccV & "," & " " & $Emiss & "," & " " & $Sip1 & "," & " " & $Sip2 & "," & " " & $Spec & "," & " " & $Current & @CRLF)
        Sleep(10000)
    WEnd
EndFunc   ;==>Current

 


App: Au3toCmd              UDF: _SingleScript()                             

Share this post


Link to post
Share on other sites
55 minutes ago, Exit said:
Func Current()
    While True
        Local $Current = ControlGetText("Window", "", 1103)
        Local $AccV = ControlGetText("Window", "", 1001)
        Local $Emiss = ControlGetText("Window", "", 1912)
        Local $Sip1 = ControlGetText("Window", "", 1388)
        Local $Sip2 = ControlGetText("Window", "", 1390)
        Local $Spec = ControlGetText("Window", "", 1312)

        FileWrite($hFileOpen, _NowTime() & "," & " " & $AccV & "," & " " & $Emiss & "," & " " & $Sip1 & "," & " " & $Sip2 & "," & " " & $Spec & "," & " " & $Current & @CRLF)
        Sleep(10000)
    WEnd
EndFunc   ;==>Current

 

Thanks, but I think I figured it out a few seconds before you posted!!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...