king_boy Posted May 1, 2006 Share Posted May 1, 2006 (edited) can any one tell me what is wrong with this code : expandcollapse popup$array=_mountlist() msgbox(0,default,$array[0][0]) ;=============================================================================== ; ; Description: lists currently mounted drives ; Syntax: _MountList() ; Parameter(s): None ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; On Failure - Returns an empty string "" if no mounted drives are found ; Note(s): The array returned is two-dimensional and is made up as follows: ; $array[0][0] = Number of Drives\Paths returned ; $array[1][0] = 1st Drive ; $array[1][1] = 1st Path ; $array[2][0] = 2nd Drive ; $array[2][1] = 2nd Path ; $array[n][0] = nth Drive ; $array[n][1] = nth Path ;=============================================================================== Func _MountList() Local $hFile, $asDriveList[1][2], $iCurrentLine, $iLine, $sDriveLetter, $sPath, $asArray ;$asDriveList[0][0] = 0 RunWait(@ComSpec & " /c SUBST > VDTEMP.DAT", @TempDir, @SW_HIDE) $hFile = FileOpen(@TempDir & "\VDTEMP.DAT", 0) If StringStripWS(FileReadLine($hFile, 1), 8) = "" Then FileClose($hFile) FileDelete(@TempDir & "\VDTEMP.DAT") Return "" EndIf While 1 $iCurrentLine = $iCurrentLine + 1 $sLine = FileReadLine($hFile, $iCurrentLine) If @error = -1 Then FileClose($hFile) FileDelete(@TempDir & "\VDTEMP.DAT") Return $asDriveList EndIf $sPath = StringStripWS(StringRight($sLine, StringLen($sLine) - StringInStr($sLine, "=>", 0, -1) - 1), 3) $sDriveLetter = StringStripWS(StringLeft($sLine, StringInStr($sLine, "=>", 0, 1) - 1), 3) ReDim $asDriveList[UBound($asDriveList) + 1][2] $asDriveList[0][0] = $asDriveList[0][0] + 1 $asDriveList[UBound($asDriveList) - 1][0] = $sDriveLetter $asDriveList[UBound($asDriveList) - 1][1] = $sPath WEnd EndFunc ;==>_MountList when i run the code i got this error : msgbox(0,default,$array^ERROR) Error:SubScript used whit non-Array variable. Edited May 1, 2006 by king_boy Link to comment Share on other sites More sharing options...
Don N Posted May 1, 2006 Share Posted May 1, 2006 are you sure this section of code is reached: If @error = -1 Then FileClose($hFile) FileDelete(@TempDir & "\VDTEMP.DAT") Return $asDriveList EndIf if not then you are not returning anything and $array would not contain anything resulting in an error when u try to display $array[0][0] _____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper Link to comment Share on other sites More sharing options...
GaryFrost Posted May 1, 2006 Share Posted May 1, 2006 (edited) being the SUBST command is for virtual drives i made a change that if no virtual drives found try for network drives Func _MountList() Local $hFile, $asDriveList[1][2], $iCurrentLine, $iLine, $sDriveLetter, $sPath, $asArray $asDriveList[0][0] = 0 RunWait(@ComSpec & " /c SUBST > VDTEMP.DAT", @ScriptDir, @SW_HIDE) $hFile = FileOpen(@ScriptDir & "\VDTEMP.DAT", 0) If StringStripWS(FileReadLine($hFile, 1), 8) = "" Then FileClose($hFile) FileDelete(@ScriptDir & "\VDTEMP.DAT") $sLine = DriveGetDrive("NETWORK") If @error Then Return @error For $x = 1 To $sLine[0] ReDim $asDriveList[$x + 1][2] $asDriveList[0][0] = $x $asDriveList[$x][0] = $sLine[$x] $asDriveList[$x][1] = DriveMapGet($sLine[$x]) Next Return $asDriveList EndIf While 1 $iCurrentLine = $iCurrentLine + 1 $sLine = FileReadLine($hFile, $iCurrentLine) If @error = -1 Then FileClose($hFile) FileDelete(@ScriptDir & "\VDTEMP.DAT") Return $asDriveList EndIf $sPath = StringStripWS(StringRight($sLine, StringLen($sLine) - StringInStr($sLine, "=>", 0, -1) - 1), 3) $sDriveLetter = StringStripWS(StringLeft($sLine, StringInStr($sLine, "=>", 0, 1) - 1), 3) ReDim $asDriveList[UBound($asDriveList) + 1][2] $asDriveList[0][0] = $asDriveList[0][0] + 1 $asDriveList[UBound($asDriveList) - 1][0] = $sDriveLetter $asDriveList[UBound($asDriveList) - 1][1] = $sPath WEnd EndFunc ;==>_MountList test code $test = _MountList() If $test = @error Then Exit For $x = 1 To $test[0][0] MsgBox(0, "test", $test[$x][0] & @LF & $test[$x][1]) Next Edited May 1, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. 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