Jump to content

how to trap error in this case


giogio
 Share

Recommended Posts

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

Link to comment
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

Link to comment
Share on other sites

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