Sign in to follow this  
Followers 0
strate

FileOpen

13 posts in this topic

I receive an error stating "Unable to open file, the maximum number of open file has been exceeded.". My FileClose statement is at the end of the part that needs it and I have one at the end of the program. Why do I get this, and what is the number of open files allowed?


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites



I receive an error stating "Unable to open file, the maximum number of open file has been exceeded.". My FileClose statement is at the end of the part that needs it and I have one at the end of the program. Why do I get this, and what is the number of open files allowed?

<{POST_SNAPBACK}>

Remarks

Up to 64 files can be open simultaneously by one AutoIt script. Exceeding this limit throws a run-time error and

So you are very likely not closing the opened files..... maybe you can post the script portion that has the issue ??

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

WinSetState("Label Data Entry", "", @SW_DISABLE)
   $LOG_EVENT = "Clicked Description Button"
   User_Log()
   $fo = FileOpen($DescFileLIST, 0)
   $desc_gui = GUICreate ("Description:", 193, 255, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 100, -1, 0x0)
   $SEARCH = GUICtrlCreateInput ("", 10, 5, 172, 20)
   WinSetOnTop("Description:", "", 1)
   $Search_button = GUICtrlCreateButton ("SEARCH", 10, 200, 60, 20)
   $DescList = GUICtrlCreateList ("", 10, 32, 172, 170, 0xA00003)
   $CLOSE2 = GUICtrlCreateButton ("OK", 123, 200, 60, 20)
   $NEW_ENTRY = GUICtrlCreateButton ("ADD ENTRY", 35, 230, 120, 20)
   GuiSetState ()
   $msg = GUIGetMsg ()
   While 4.8
      While $msg <> $GUI_EVENT_CLOSE
         $msg = GUIGetMsg ()
         $MOUSE_MSG = GUIGetCursorInfo ($desc_gui)
         If $MOUSE_MSG[4] = "4104" And $MOUSE_MSG[2] = 1 Then
            $msg = $CLOSE2
         EndIf
         If ControlGetFocus("Description:", "") = "Edit1" Then
            HotKeySet("{ENTER}", "Description_List_Enter")
         Else
            HotKeySet("{ENTER}")
         EndIf
         Select
            Case $msg = $NEW_ENTRY
               $SEARCH_TEXT = StringUpper(GUIRead ($SEARCH))
               If $SEARCH_TEXT <> "" Then
                  WinSetOnTop("Description:", "", 0)
                  $Confirm = MsgBox(4 + 8192,"Confirm","Are you sure you want to add "&$SEARCH_TEXT& " to the program?")
                  WinSetOnTop("Description:", "", 1)
                  If $Confirm = 7 Then
                     WinSetState("Description:", "", @SW_ENABLE)
                     ControlSetText("Description:", "", $SEARCH, "")
                     GUICtrlSetState ($SEARCH, $GUI_FOCUS)
                     ExitLoop(1)
                  ElseIf $Confirm = 6 Then
                     FileWriteLine("G:\Packaging\Labels\LVWIN70\QBASIC\DESC_1.txt", '"' & $SEARCH_TEXT & '"')
                     WinSetOnTop("Description:", "", 0)
                     WinSetState("Description:", "", @SW_HIDE)
                     MsgBox(0 + 8192, "Notice", $SEARCH_TEXT & " added to description file.")
                     WinSetOnTop("Description:", "", 1)
                     ControlSetText("Label Data Entry", "", $DESC_BUTTON, $SEARCH_TEXT)
                     GUISwitch ("Description:")
                     GUIDelete ()
                     WinSetState("Label Data Entry", "", @SW_ENABLE)
                     $LOG_EVENT = "Added Description - " & $SEARCH_TEXT
                     User_Log()
                     GUICtrlSetState ($DUE, $GUI_FOCUS)
                     ExitLoop (2)
                  EndIf
               Else
                  WinSetOnTop("Description:", "", 0)
                  WinSetState("Description:", "", @SW_HIDE)
                  MsgBox(0 + 8192, "Notice", "Please Enter Description.")
                  WinSetState("Description:", "", @SW_SHOW)
                  WinSetOnTop("Description:", "", 1)
                  GUICtrlSetState ($SEARCH, $GUI_FOCUS)
               EndIf
            Case $msg = $GUI_EVENT_CLOSE
               GUIDelete ()
               WinSetState("Label Data Entry", "", @SW_ENABLE)
               ExitLoop (2)
            Case $msg = $DESC_BUTTON
               If WinExists("Description:", "") Then
                  WinActivate("Description:", "")
               EndIf
            Case $msg = $CLOSE2
               $LOG_EVENT = "Closed Description Search Dialog"
               User_Log()
               $CLOSE_BUTTON_TEXT = GUIRead ($DescList)
               If $CLOSE_BUTTON_TEXT <> "" Then
                  ControlSetText("Label Data Entry", "", $DESC_BUTTON, $CLOSE_BUTTON_TEXT)
               EndIf
               WinSetState("Label Data Entry", "", @SW_ENABLE)
               GUIDelete ()
               $LOG_EVENT = "Searched Descriptions for - " & $CLOSE_BUTTON_TEXT
               User_Log()
               GUICtrlSetState ($DUE, $GUI_FOCUS)
               ExitLoop(2)
            Case $msg = $Search_button
               $SEARCH_STRING = GUIRead ($SEARCH)
               $DESCFILE = FileOpen($DescFileLIST, 0)
               If $DESCFILE = -1 Then
                  MsgBox(0, "Error", "Unable to open file.")
                  $LOG_EVENT = "Unable to open description file"
                  User_Log()
                  Exit
               EndIf
               While 5.0
                  $line = FileReadLine($DESCFILE)
                  $line = StringTrimLeft(StringTrimRight($line, 1), 1)
                  If @error = -1 Then ExitLoop
                  If StringLeft($line, StringLen(GUIRead ($SEARCH))) = $SEARCH_STRING Then
                     $STRING_LENGTH = StringLen($line)
                     $list = $list & $line & "|"
                  EndIf
                  If StringLeft($line, 2) = "" Then ExitLoop
               Wend
               FileClose($DescFileLIST)
               GUICtrlSetData ($DescList, $list)
               $list = "|"
         EndSelect
      Wend
   Wend
   GUICtrlSetState ($DUE, $GUI_FOCUS)
   HotKeySet("{ENTER}")

Sorry about it being sloppy.

This maybe dumb but after looking at it I should have a FileClose after the last Wend right? If you can find anything that could be improved feel free to comment.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

I'm looking at the end part right now...I don't understand a few things.

Why are you using 'While 5.0'. You usually do a 'While 1' (infinite loop) or 'While $variable <> $somethingelse'.

Also, You use HotKeySet() without setting the function to run when {ENTER} is pressed.

Also, in $msg = $Search_button, you reopen the same file in the same mode as in the beginning.

As for the HotKeySet, you do that in a statement near the top as well, which isn't necessary either.


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Func DESC_BUTTON()
   Opt ("GuiOnEventMode", 0)
   WinSetState("Label Data Entry", "", @SW_DISABLE)
   $LOG_EVENT = "Clicked Description Button"
   User_Log()
   $desc_gui = GUICreate ("Description:", 193, 255, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 100, -1, 0x0)
   $SEARCH = GUICtrlCreateInput ("", 10, 5, 172, 20)
   WinSetOnTop("Description:", "", 1)
   $Search_button = GUICtrlCreateButton ("SEARCH", 10, 200, 60, 20)
   $DescList = GUICtrlCreateList ("", 10, 32, 172, 170, 0xA00003)
   $CLOSE2 = GUICtrlCreateButton ("OK", 123, 200, 60, 20)
   $NEW_ENTRY = GUICtrlCreateButton ("ADD ENTRY", 35, 230, 120, 20)
   GuiSetState ()
   $msg = GUIGetMsg ()
   While 4.8
      While $msg <> $GUI_EVENT_CLOSE
         $msg = GUIGetMsg ()
         $MOUSE_MSG = GUIGetCursorInfo ($desc_gui)
         If $MOUSE_MSG[4] = "4104" And $MOUSE_MSG[2] = 1 Then
            $msg = $CLOSE2
         EndIf
         If ControlGetFocus("Description:", "") = "Edit1" Then
            HotKeySet("{ENTER}", "Description_List_Enter")
         Else
            HotKeySet("{ENTER}")
         EndIf
         Select
            Case $msg = $NEW_ENTRY
               $SEARCH_TEXT = StringUpper(GUIRead ($SEARCH))
               If $SEARCH_TEXT <> "" Then
                  WinSetOnTop("Description:", "", 0)
                  $Confirm = MsgBox(4 + 8192,"Confirm","Are you sure you want to add "&$SEARCH_TEXT& " to the program?")
                  WinSetOnTop("Description:", "", 1)
                  If $Confirm = 7 Then
                     WinSetState("Description:", "", @SW_ENABLE)
                     ControlSetText("Description:", "", $SEARCH, "")
                     GUICtrlSetState ($SEARCH, $GUI_FOCUS)
                     ExitLoop(1)
                  ElseIf $Confirm = 6 Then
                     FileWriteLine("G:\Packaging\Labels\LVWIN70\QBASIC\DESC_1.txt", '"' & $SEARCH_TEXT & '"')
                     WinSetOnTop("Description:", "", 0)
                     WinSetState("Description:", "", @SW_HIDE)
                     MsgBox(0 + 8192, "Notice", $SEARCH_TEXT & " added to description file.")
                     WinSetOnTop("Description:", "", 1)
                     ControlSetText("Label Data Entry", "", $DESC_BUTTON, $SEARCH_TEXT)
                     GUISwitch ("Description:")
                     GUIDelete ()
                     WinSetState("Label Data Entry", "", @SW_ENABLE)
                     $LOG_EVENT = "Added Description - " & $SEARCH_TEXT
                     User_Log()
                     GUICtrlSetState ($DUE, $GUI_FOCUS)
                     ExitLoop (2)
                  EndIf
               Else
                  WinSetOnTop("Description:", "", 0)
                  WinSetState("Description:", "", @SW_HIDE)
                  MsgBox(0 + 8192, "Notice", "Please Enter Description.")
                  WinSetState("Description:", "", @SW_SHOW)
                  WinSetOnTop("Description:", "", 1)
                  GUICtrlSetState ($SEARCH, $GUI_FOCUS)
               EndIf
            Case $msg = $GUI_EVENT_CLOSE
               GUIDelete ()
               WinSetState("Label Data Entry", "", @SW_ENABLE)
               ExitLoop (2)
            Case $msg = $DESC_BUTTON
               If WinExists("Description:", "") Then
                  WinActivate("Description:", "")
               EndIf
            Case $msg = $CLOSE2
               $LOG_EVENT = "Closed Description Search Dialog"
               User_Log()
               $CLOSE_BUTTON_TEXT = GUIRead ($DescList)
               If $CLOSE_BUTTON_TEXT <> "" Then
                  ControlSetText("Label Data Entry", "", $DESC_BUTTON, $CLOSE_BUTTON_TEXT)
               EndIf
               WinSetState("Label Data Entry", "", @SW_ENABLE)
               GUIDelete ()
               $LOG_EVENT = "Searched Descriptions for - " & $CLOSE_BUTTON_TEXT
               User_Log()
               GUICtrlSetState ($DUE, $GUI_FOCUS)
               ExitLoop(2)
            Case $msg = $Search_button
               $SEARCH_STRING = GUIRead ($SEARCH)
               $fo = FileOpen($DescFileLIST, 0)
               If $fo = -1 Then
                  MsgBox(0, "Error", "Unable to open file.")
                  $LOG_EVENT = "Unable to open description file"
                  User_Log()
                  Exit
               EndIf
               While 1
                  $line = FileReadLine($fo)
                  $line = StringTrimLeft(StringTrimRight($line, 1), 1)
                  If @error = -1 Then ExitLoop
                  If StringLeft($line, StringLen(GUIRead ($SEARCH))) = $SEARCH_STRING Then
                     $STRING_LENGTH = StringLen($line)
                     $list = $list & $line & "|"
                  EndIf
                  If StringLeft($line, 2) = "" Then ExitLoop
               Wend
               GUICtrlSetData ($DescList, $list)
               $list = "|"
               FileClose($fo)
         EndSelect
      Wend
   Wend
   GUICtrlSetState ($DUE, $GUI_FOCUS)
   HotKeySet("{ENTER}")
   Opt ("GuiOnEventMode", 1)
EndFunc  ;==>DESC_BUTTON

Func Description_List_Enter()
   $msg = $Search_button
   ControlFocus("Description:", "", "ListBox1")
EndFunc  ;==>Description_List_Enter

Any better yet?


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

Is it possible to monitor the number of files that are open? I thought the changes solved the problem; but lastnight third shift had the same problem after going four nights without the error?


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

I added a MsgBox afterthe open statement - - MsgBox(4096,'debug:' , '$fo:' & $fo) it returns $fo:1 is this because their is only one file open?


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

Is it possible to monitor the number of files that are open? I thought the changes solved the problem; but lastnight third shift had the same problem after going four nights without the error?

<{POST_SNAPBACK}>

Are you using any other FileOpen() or FileFindFirstFile() in your script ?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Can you test for an open file?


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

Can you test for an open file?

<{POST_SNAPBACK}>

there is no command for it..

did you see my other post just before yours ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Are you using any other FileOpen() or FileFindFirstFile() in your script ?

<{POST_SNAPBACK}>

I did and they never even had close statements, but I've fixed that.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

If the files I'm opening are on a network would this prevent them from being closed properly?


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

If the files I'm opening are on a network would this prevent them from being closed properly?

<{POST_SNAPBACK}>

No, don't think so.

Are you sure you always hit the fileclose() .... no exitloop or anything like that before the Fileclose() ?

If you want you can pm the source so i can have a quick look at it ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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