Jump to content

Exit function with FileOpen


Go to solution Solved by javiwhite,

Recommended Posts

Hello :)

Im having a problem with Exit

When the FileOpen FileOpenDialog was presenting

I tried to Exit with the tray but I need to press Cancel/Close on FileOpen FileOpenDialog to make Autoit Exit

#include <TrayConstants.au3>
#NoTrayIcon
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
Global $iExit = TrayCreateItem("Exit")
TraySetState(1)
TrayItemSetOnEvent($iExit,"_exit")
$checking = False
While $checking = False
$FileOpen = FileOpenDialog("Open Texts", @UserProfileDir , "Text (*.txt)")
If Not @error Then
    MsgBox(0,"Text Opened","")
$checking = True
EndIf
WEnd

While 1
    Sleep(1)
WEnd

Func _exit()
    Exit 0
EndFunc

Sorry for my bad english :thumbsup:

____________

Edit : Function Mistake o:)

Edited by ghost11996

[color=rgb(255,0,0);]C[/color][color=rgb(255,140,0);]a[/color][color=rgb(255,215,0);]n[/color] [color=rgb(255,255,0);]i[/color] [color=rgb(175,238,238);]e[/color][color=rgb(0,255,255);]a[/color][color=rgb(64,224,208);]t[/color] [color=rgb(0,0,205);]S[/color][color=rgb(0,0,255);]i[/color][color=rgb(0,0,128);]g[/color][color=rgb(75,0,130);]n[/color][color=rgb(128,0,128);]at[/color][color=rgb(238,130,238);]u[/color][color=rgb(221,160,221);]r[/color][color=rgb(230,230,250);]e[/color] [color=rgb(0,255,0);]?[/color] :ermm: [color=rgb(0,255,0);]Project: Mini Youtube BETA[/color]

Link to comment
Share on other sites

You need to use something like this:

$FileOpen = FileOpenDialog("Open Texts", @UserProfileDir , "Text (*.txt)")
If @error <> 0 Then Exit

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

I believe the issue is due to the fact that AutoIT doesn't support multithreading.

When the dialog box is open, The script will wait until the user has finished with the dialog box before processing any further requests.

The easiest way to see what i mean is, Add a consoleWrite() to your exit function, and then try and see when exactly the exit code runs. (i believe it will run as soon as the FileOpenFolder is closed.)

The way around this would be to have two separate scripts, The parent and child; With the child being the FileOpenFolder. the parent script would call the FileOpenFolder script, and then, when required, Kill the script and then exit itself...

Here is your script that i modified and tested with, and it works for me:

parent:

#include <TrayConstants.au3>
#NoTrayIcon
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
Global $iExit = TrayCreateItem("Exit")
TraySetState(1)
TrayItemSetOnEvent($iExit,"_exit")
run(@workingDir & "\FileOpenTxt.exe")

While 1
    Sleep(1)
WEnd

Func _exit()
   ProcessClose("FileOpenTxt.exe")
       Exit 0

EndFunc

Child

$checking = False
if $checking = False Then
   $FileOpen = FileOpenDialog("Open Texts", @UserProfileDir , "Text (*.txt)")
   If Not @error Then
      MsgBox(0,"Text Opened","")
   $checking = True
   EndIf
EndIf

In this example however, I did have to compile the script as an exe called FileOpenTxt.exe (this is so it would have its own process in task manager), But you could experiment with WinClose.

As the saying goes; There's always more than one way to skin a cat.

also, why do you have a while loop running around the folderopendialog? The dialog should pause the script until the user exits the command anyway. If you're looking too ensure they select a file, just set the options param to 1 and it should achieve the same result Link
 

I hope this helps :)

-Javi

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Link to comment
Share on other sites

@JohnOne: Yea Sorry My mistake >_<

@water: I think you misunderstand my question...

@Javiwhite:

Nice resolution I guess I will put it in my code Thanks

Ps: The code was just an example for asking >_<

[color=rgb(255,0,0);]C[/color][color=rgb(255,140,0);]a[/color][color=rgb(255,215,0);]n[/color] [color=rgb(255,255,0);]i[/color] [color=rgb(175,238,238);]e[/color][color=rgb(0,255,255);]a[/color][color=rgb(64,224,208);]t[/color] [color=rgb(0,0,205);]S[/color][color=rgb(0,0,255);]i[/color][color=rgb(0,0,128);]g[/color][color=rgb(75,0,130);]n[/color][color=rgb(128,0,128);]at[/color][color=rgb(238,130,238);]u[/color][color=rgb(221,160,221);]r[/color][color=rgb(230,230,250);]e[/color] [color=rgb(0,255,0);]?[/color] :ermm: [color=rgb(0,255,0);]Project: Mini Youtube BETA[/color]

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