Jump to content

Avoiding Msgbox On Error Detected ?


Recommended Posts

  • Developers

Which MessageBox or specific Error do you refer to ?

Most errors can be avoided like for Run/Runwait you can specify :

Opt("RunErrorsFatal", 0)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

in fact, i try to execute $COMMANDLINE witch is sended in a command line parameter

my application 's name : suclient.exe

2 exemples of parameters:

- Suclient audit.cmd

- Suclient "Dir c:\"

in case of lanching a Batch file, there's no problem

but in case of Suclient "dir.cmd", the command is failed because the good correct command line must be : Suclient " cmd /C dir c:\"

i looking for how to detect that the parameter is betwin " " ?

; a part of my code

$COMMANDLINE = $CmdLine[1]
RunWait ($COMMANDLINE)
Edited by lnx2050
Link to comment
Share on other sites

  • Developers

This is how you can avoid errors with your code:

Opt("RunErrorsFatal", 0); no run errors
; if one parameter is specified then run the program 
If $CmdLine[0] = 1 then
  ; put " around the first parameter to be able to handle long file names
   Run( '"' & $CmdLine[1] & '"')
   if @error then
    ; error running the program code
   endif
else
  ; no parameter specified code
endif

EDIT

You can also take all parameters, in otther words .. not worry about the " on the command line and just add the whole thing together:

Opt("RunErrorsFatal", 0); no run errors
; if one parameter is specified then run the program 
If $CmdLine[0] > 0 then
  $command= ""
  for $x = 1 to $CmdLine[0]
     $command= $command & " " $CmdLine[$x]
  Next 
 ; put " around the first parameter to be able to handle long file names
   Run( '"' & $command & '"')
   if @error then
    ; error running the program code
   endif
else
 ; no parameter specified code
endif
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Many errors can be fixed by better coding.

example:

;bad code
$VAR = $CmdLine[1]
Msgbox(4096, "Hello ",$VAR)

if you wanted to exit on error better code would be:

if $CmdLine[0] < 1 then exit
$VAR = $CmdLine[1]
Msgbox(4096, "Hello ",$VAR)

or

If ubound ($CmdLine)=1 Then exit
$VAR = $CmdLine[1]
MsgBox(4096, "Hello ",$VAR)

you can also use:

IsArray

IsDeclared

IsFloat

IsInt

IsNumber

IsString

and

MustDeclareVars might come in handy for ya

RunErrorsFatal is not a substitute for thoughtful coding. ex.

Opt("RunErrorsFatal", 0)
$VAR = $CmdLine[1]
Msgbox(4096, "Hello ",$VAR)

RunErrorsFatal(0)....Sets if the script should terminate with a fatal error if a Run/RunWait function fails due to bad paths/file not found/Bad login IDs:

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

yes, but my problem is to detect the "" in the parameter.

The $Cmdline[1] is saving the parameter within the ""

if i send in dos prompt : Suclient "dir c:\"

the $Cmdline[1] is dir c:\ but not "dir c:\"

so how to detect the "" ?

that's all my pbm :whistle:

Ln.

Link to comment
Share on other sites

  • Developers

check my EDIT in the previous post.... that should take care of that issue... (i think :whistle: )

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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