meetrix Posted April 30, 2006 Share Posted April 30, 2006 I have the following script and it's not working correctly. Can someone tell me why? The main idea is set a variable; prompt the user for input. Have the script search first , to make sure if variable=files already exist. If exist, to prompt to either over-write, if not to create one. Then message the user that the scripts has completed. $var = EnvSet("snum", "Serial Number") $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If FileExists("V:"& "\" & ($var) & ".log" )Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") EndIf If $answer = 6 Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial NUmber has been Created.") Exit EndIf Link to comment Share on other sites More sharing options...
Uten Posted April 30, 2006 Share Posted April 30, 2006 I have the following script and it's not working correctly. Can someone tell me why? The main idea is set a variable; prompt the user for input. Have the script search first , to make sure if variable=files already exist. If exist, to prompt to either over-write, if not to create one. Then message the user that the scripts has completed. $var = EnvSet("snum", "Serial Number") $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If FileExists("V:"& "\" & ($var) & ".log" )Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") EndIf If $answer = 6 Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial NUmber has been Created.") Exit EndIfAs fare as I can see you do not do anything if the file does not exists. Have not tested the code: $var = EnvSet("snum", "Serial Number") $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If FileExists("V:"& "\" & ($var) & ".log" )Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") If $answer = 6 Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial NUmber has been Created.") Exit EndIf Else ;File did not exist, create it? EndIf Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 Thank you. I will try it. Questions: When prompted to enter data, if they decide to press "cancel" button, how can I set the script to exit instead of proceeding? If when prompted to replace file, the "yes" will proceed to continue, but if they decide to choose "No", how can I set to script to either exit and return back to the prompt? As fare as I can see you do not do anything if the file does not exists. Have not tested the code: $var = EnvSet("snum", "Serial Number") $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If FileExists("V:"& "\" & ($var) & ".log" )Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") If $answer = 6 Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial NUmber has been Created.") Exit EndIf Else ;File did not exist, create it? EndIf Link to comment Share on other sites More sharing options...
jvanegmond Posted April 30, 2006 Share Posted April 30, 2006 $var = EnvSet("snum", "Serial Number") $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If $var = "" Then Exit EndIf If FileExists("V:"& "\" & ($var) & ".log" )Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") If $answer = 6 Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial NUmber has been Created.") Exit EndIf Else ;File did not exist, create it? EndIf github.com/jvanegmond Link to comment Share on other sites More sharing options...
Uten Posted April 30, 2006 Share Posted April 30, 2006 Thank you. I will try it. Questions:When prompted to enter data, if they decide to press "cancel" button, how can I set the script to exit instead of proceeding? If when prompted to replace file, the "yes" will proceed to continue, but if they decide to choose "No", how can I set to script to either exit and return back to the prompt?Just check the return value from the msgbox. The help file is your friend (And probably use flag=3 rather than 4) Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 Thank you. I will try it.. It's the little things that kill and takes the most time to figure out. By the way, I'm trying to learn guitar. My fav band is Megadeth.. Take care. $var = EnvSet("snum", "Serial Number") $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If $var = "" Then Exit EndIf If FileExists("V:"& "\" & ($var) & ".log" )Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") If $answer = 6 Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial NUmber has been Created.") Exit EndIf Else ;File did not exist, create it? EndIf Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 I will search more and play with the scripts. Being a beginner in scripting is not fun, but eventually once all works together you feel proud.Well take care and ya next time, but if you have other ideas, let me know.Just check the return value from the msgbox. The help file is your friend (And probably use flag=3 rather than 4) Link to comment Share on other sites More sharing options...
jvanegmond Posted April 30, 2006 Share Posted April 30, 2006 Cool mate, my fav band is Rage Against The Machine. If you feel you're good enough to let me hear your playing, try to record a little bit once and don't hesitate to send me a message github.com/jvanegmond Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 Updated File, Let me know what you think. I need one more thing. I need to print or open the file in Notepad in order to print it.. Any thoughts? Let me know. $var = EnvSet("snum", "Serial Number") ;Prompt For Serial Number $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") ; If answered yes it script will continue if $var = "" Then Exit EndIf If FileExists("V:"& "\" & ($var) & ".log" )Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") if $answer = 7 Then MsgBox(48, "Stopped!", "You don't want to proceed, Click OK to exit") Exit EndIf If $answer = 6 Then $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial Number has been Created.") run("notepad.exe","V:"& "\" & ($var) & ".log", 2) Exit EndIf Else ;File did not exist, create it? $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial Number has been Created.") EndIf Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted April 30, 2006 Share Posted April 30, 2006 _Fileprint lol Link to comment Share on other sites More sharing options...
skippynz Posted April 30, 2006 Share Posted April 30, 2006 Updated File, Let me know what you think. I need one more thing. I need to print or open the file in Notepad in order to print it.. Any thoughts? Let me know. $var = EnvSet("snum", "Serial Number") ;Prompt For Serial Number $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") ; If answered yes it script will continue if $var = "" Then Exit EndIf If FileExists("V:"& "\" & ($var) & ".log" )Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") if $answer = 7 Then MsgBox(48, "Stopped!", "You don't want to proceed, Click OK to exit") Exit EndIf If $answer = 6 Then $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial Number has been Created.") run("notepad.exe","V:"& "\" & ($var) & ".log", 2) Exit EndIf Else ;File did not exist, create it? $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial Number has been Created.") EndIf from the help file #include <File.au3> $file = FileOpenDialog("Print File", "", "Text Documents (*.txt)", 1) If @error Then Exit $print = _FilePrint($file) If $print Then MsgBox(0, "Print", "The file was printed.") Else MsgBox(0, "Print", "Error: " & @error & @CRLF & "The file was not printed.") EndIf Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 Thank you.. I will learn this unknown language sooner or later.. Take care.. oh mighty one. _Fileprint lol Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 Thank you. I appreciate everyones help..I will try it. Have a good day. from the help file #include <File.au3> $file = FileOpenDialog("Print File", "", "Text Documents (*.txt)", 1) If @error Then Exit $print = _FilePrint($file) If $print Then MsgBox(0, "Print", "The file was printed.") Else MsgBox(0, "Print", "Error: " & @error & @CRLF & "The file was not printed.") EndIf Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 When setting the _FilePrint, the script does not work. I get the following message. I search for the _Fileprint and cannot find in the help files. : ERROR: _FilePrint(): undefined function. _FilePrint ($file) Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted April 30, 2006 Share Posted April 30, 2006 u didnt include file.au3 #include <file.au3> Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 I tried it and still not working.. I am running the script alone and even the error message box does not appear. ????? u didnt include file.au3 #include <file.au3> Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted April 30, 2006 Share Posted April 30, 2006 post ur script Link to comment Share on other sites More sharing options...
meetrix Posted April 30, 2006 Author Share Posted April 30, 2006 $var = EnvSet("snum", "Serial Number");Prompt For Serial Number$var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK"); If answered yes it script will continueif $var = "" Then ExitEndIfIf FileExists("V:"& "\" & ($var) & ".log" )Then ;MsgBox(4, "File Already Exist", "What do you want to do?") $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") if $answer = 7 Then MsgBox(48, "Stopped!", "You don't want to proceed, Click OK to exit") ExitEndIf If $answer = 6 Then $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial Number has been Created.") $file = FileOpen("test.txt", 0) Exit EndIf Else ;File did not exist, create it? $file = Fileopen("V:"& "\" & ($var) & ".log", 2) MsgBox(4096,"Good Job", "Serial Number has been Created.")EndIf;Print File$file = FileopenDiaglog("V:"& "\" & ($var) & ".log", 2)If @error Then Exit$print = _FilePrint($file)If $print Then MsgBox(0, "Print", "The file was printed.")Else MsgBox(0, "Print", "Error: " & @error & @CRLF & "The file was not printed.")EndIfpost ur script Link to comment Share on other sites More sharing options...
herewasplato Posted April 30, 2006 Share Posted April 30, 2006 (edited) What good is this line if you are going to write over $var with the input box? $var = EnvSet("snum", "Serial Number") What are you hoping to do with that line of code? I do not think that this code will do what you want, but then again - I'm not sure what you want. The code is just to show you that you need only check for the answer "No" if you are going to exit the entire script if the user answers no.$var = "" ;Prompt For Serial Number $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If $var = "" Then Exit If FileExists("V:" & "\" & $var & ".log") Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") If $answer = 7 Then ;do if answer = no MsgBox(48, "Stopped!", "You don't want to proceed, Click OK to exit") Exit;ends script EndIf EndIf ;do if answer = yes $file = FileOpen("V:" & "\" & ($var) & ".log", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;you now have a totally empty fileUnless there is more to your code, I don't see where you have anything to print... Edit: From the help file under FileOpen 2 = Write mode (erase previous contents) ...so nothing to print Not to insult, but just incase you are laboring under this misconception: FileOpen is not the same as selecting File and then Open in notepad Edited April 30, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
meetrix Posted May 1, 2006 Author Share Posted May 1, 2006 Hi, Thank you for your feed back. I respect your observation and critisims. I am new to autoit, but I am trying to develope some code for my work. And with the development it comes the learning experience. I am good with dos scripts, but I'm trying to improve my skills. The Idea I have is the following: 1. Create a variable (or string) 2. Prompt the user to type in a Serial Number. But if the user wants to exit, then the end the script. But if they want to continue to be able to. 3. Verify if that serial number exist, if exist to prompt to over-write or to continue if it does not exist. 4. Take the serial number and create a file either .log or .txtr with that serial number. 5. Then find the file and either open it with a notepad application, or send it directly to the printer. Do you have a better way of writing the script. Please let me know. What good is this line if you are going to write over $var with the input box? $var = EnvSet("snum", "Serial Number") What are you hoping to do with that line of code? I do not think that this code will do what you want, but then again - I'm not sure what you want. The code is just to show you that you need only check for the answer "No" if you are going to exit the entire script if the user answers no.$var = "" ;Prompt For Serial Number $var = InputBox("Get Serial Number", "Please Type or Scan Serial Number, click OK") If $var = "" Then Exit If FileExists("V:" & "\" & $var & ".log") Then $answer = MsgBox(4, "File Already Exist", "Do you want to replace it?") If $answer = 7 Then ;do if answer = no MsgBox(48, "Stopped!", "You don't want to proceed, Click OK to exit") Exit;ends script EndIf EndIf ;do if answer = yes $file = FileOpen("V:" & "\" & ($var) & ".log", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;you now have a totally empty fileUnless there is more to your code, I don't see where you have anything to print... Edit: From the help file under FileOpen 2 = Write mode (erase previous contents) ...so nothing to print Not to insult, but just incase you are laboring under this misconception: FileOpen is not the same as selecting File and then Open in notepad Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now