Sign in to follow this  
Followers 0
giogio

how to trap error in this case

8 posts in this topic

func FindRemovableDisk()

; THIS DOESN'T WORK*************************************

$label =$CmdLine[2]

MsgBox(4096, "", $label)

if $label="" then ; if command line not present exit

;*****EXIT*****

Sleep(10)

Exit 200

EndIf

;*******************************************

$var = DriveGetDrive("REMOVABLE")

$FlagFunc="ok"

If Not @error then

;MsgBox(4096, "", "Found " & $var[0] & " drives")

For $i = 1 To $var[0]

If DriveGetLabel($var[$i]) = $label Then

ConsoleWrite ($var[$i]); no error

;*****EXIT*****

Sleep(10)

Exit 200

EndIf

Next

EndIf

consoleWrite ("@error") ; error

EndFunc

PEASE HELP ME

Share this post


Link to post
Share on other sites



where are you defining $CmdLine[2]?

When the program is called with parameters from the command line?

Share this post


Link to post
Share on other sites

FROM THE CMD.EXE I RUN C:\MYSCRIPT.EXE "MYPARAMETER"

IF I FORGOT THE PARAMENTER I GET THIS AUTOIT ERROR:

LINE-1:

ERROR: ARRAY VARIABLE HAS INCORRECT NUMBER OF SUBSRIPTS OR SUBSCRIPT DIMENSION RANGE EXCEEDED.

Share this post


Link to post
Share on other sites

You don't define it, it is a constant. There has been many questions about why it isn't @CmdLine, but I think its because its an array.

$CmdLine[0] Contains the number of parameters passed to your script

$CmdLine[1] Contains parameter 1

$CmdLine[2] Contains parameter 2

This is explained in the Help file under Using Autoit > Command Line Parameters

Share this post


Link to post
Share on other sites

Your script is waiting for the second parameter though. If you want to run "C:\MYSCRIPT.EXE "MYPARAMETER"" , you need to change $CmdLine[2] to $CmdLine[1].

$CmdLine[0] hold how many parameters the script was called with.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Func FindRemovableDisk()

    If $CmdLine[0] = 0 Then
        Return 0
    EndIf
    
    $label = $CmdLine[2]
    MsgBox(4096, "", $label)
    If $label = "" Then 
        ; if command line not present exit
        ;*****EXIT*****
        Sleep(10)
        Exit 200
    EndIf
    ;*******************************************

    $var = DriveGetDrive("REMOVABLE")
    $FlagFunc = "ok"
    If Not @error Then
        ;MsgBox(4096, "", "Found " & $var[0] & " drives")
        For $i = 1 To $var[0]
            If DriveGetLabel($var[$i]) = $label Then
                ConsoleWrite($var[$i]); no error
                ;*****EXIT*****
                Sleep(10)
                Exit 200
            EndIf
        Next
    EndIf
    ConsoleWrite("@error") ; error
EndFunc   ;==>FindRemovableDisk

Edited by weaponx

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