Sign in to follow this  
Followers 0
Jochem

loop through empty array gives error

3 posts in this topic

I have some problems when looping through an array when it is empty. It kills my script. Offcourse a can add a fake entry sometimes, but actually I would prefer that @error the script continous.

Is there a way to do this?

this is an example script: and whene people don`t have a cd drive the script craches.

$anetdrives = DriveGetDrive("NETWORK")
For $snetdrive In $anetdrives
    DriveMapDel($snetdrive)
Next
$acddrives = DriveGetDrive("CDROM")
For $scddrive In $acddrives
    $scddrivetxt = StringTrimRight($scddrive, 1)
    RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $scddrive & " /L >c:\temp\" & $scddrivetxt & ".txt", "", @SW_HIDE)
Next
For $scddrive In $acddrives
    RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $scddrive & " /D", "", @SW_HIDE)
Next
For $scddrive In $acddrives
    $CDascistart = $CDascistart + 1
    $cddriveletter = Chr($CDascistart)
    $scddrivetxt = StringTrimRight($scddrive, 1)
    $cdvolguid = FileReadLine("c:\temp\" & $scddrivetxt & ".txt", 1)
    RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $cddriveletter & ":" & $cdvolguid, "", @SW_HIDE)
    FileDelete("c:\temp\" & $scddrivetxt & ".txt")
Next
$aremdrives = DriveGetDrive("REMOVABLE")
For $sremdrive In $aremdrives
    $sremdrivetxt = StringTrimRight($sremdrive, 1)
    RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $sremdrive & " /L >c:\temp\" & $sremdrivetxt & ".txt", "", @SW_HIDE)
Next
For $sremdrive In $aremdrives
    RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $sremdrive & " /D", "", @SW_HIDE)
Next
For $sremdrive In $aremdrives
    $REMOVABLEascistart = $REMOVABLEascistart + 1
    $remdriveletter = Chr($REMOVABLEascistart)
    $sremdrivetxt = StringTrimRight($sremdrive, 1)
    $remvolguid = FileReadLine("c:\temp\" & $sremdrivetxt & ".txt", 1)
    RunAsWait($user, @LogonDomain, $pw, "", '"' & @ComSpec & '" /c ' & "mountvol " & $remdriveletter & ":" & $remvolguid, "", @SW_HIDE)
    FileDelete("c:\temp\" & $sremdrivetxt & ".txt")
Next

Share this post


Link to post
Share on other sites



check the size of the array using UBound before accessing it.

or better, check @error after calling DriveGetDrive

Success: Returns an array of strings (drive letter followed by colon) of drives found. The zeroth array element contains the number of drives.

Failure: Returns "" and sets @error to 1.

The don't set @error so they can type more documentation :(

Share this post


Link to post
Share on other sites

check the size of the array using UBound before accessing it.

or better, check @error after calling DriveGetDrive

Success: Returns an array of strings (drive letter followed by colon) of drives found. The zeroth array element contains the number of drives.

Failure: Returns "" and sets @error to 1.

The don't set @error so they can type more documentation :(

ah oke, that simple; thanx!

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