Jump to content

ignores completely whether a file exists


Recommended Posts

it just ignores this completely and doesn't msg box or create the new file at all, it should extract variables from a txt document which it does but if this txt document doesn't exist i want it to create the txt document and quit the script so the user can enter the details into the txt document and restart the script.

If FileExists("adsettings.txt") = 0  Then
MsgBox(0, "Error", "adsettings.txt doesn't exist and has just been created, please add your details to it before running again.")
$file = FileOpen("adsettings.txt",2)
FileWriteLine($file,1) = "Directory"
FileWriteLine($file,2) = "Username 1"
FileWriteLine($file,3) = "Password 1"
FileClose($file)
Exit
EndIf
Dim $file = FileOpen("adsettings.txt",0)
Dim $ABBYY = FileReadLine($file,1)
Dim $username = FileReadLine($file,2)
Dim $pw = FileReadLine($file,3)
FileClose($file)

HotKeySet( "{F8}", "paused")
HotKeySet( "{F7}", "login")

while 1
    sleep(100)
WEnd

Func paused()
$status = "paused"
    while $status = "paused"
    sleep(100)
WEnd
EndFunc

Func login()
$status = "started"
Link to comment
Share on other sites

RE: The first post.

Shift your Dim lines to the top of your script and yeah, format of FileWriteLine should be changed to

FileWriteLine($file,"Directory") instead of FileWriteLine($file,1) = "Directory"

Link to comment
Share on other sites

try

If Not FileExists("adsettings.txt") Then

edit: If FileExists("adsettings.txt") = 0 Then

worked for me but only after I rewrote the line...

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

thnx turns out i meant to use _FileWriteToLine instead actually not much difference but meh, anyway it still seems to not give me a msg box or anything or create the file like this, as if its ignoring the If FileExists line completely:

#include <File.au3>
Dim $file = FileOpen("adsettings.txt",0)
Dim $ABBYY = FileReadLine($file,1)
Dim $username = FileReadLine($file,2)
Dim $pw = FileReadLine($file,3)
If FileExists("adsettings.txt") = 0  Then
MsgBox(0, "Error", "adsettings.txt doesn't exist and has just been created, please add your details to it before running again.")
_FileCreate("adsettings.txt")
FileOpen("adsettings.txt",2)
_FileWriteToLine($file,1,"Directory",1)
_FileWriteToLine($file,2,"Username 1",1)
_FileWriteToLine($file,3,"Password 1",1)
FileClose($file)
Exit
EndIf
FileClose($file)

HotKeySet( "{F8}", "paused")
HotKeySet( "{F7}", "login")

while 1
    sleep(100)
WEnd

Func paused()
$status = "paused"
    while $status = "paused"
    sleep(100)
WEnd
EndFunc

Func login()
$status = "started"
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...