|
Post by rcamp48 on Dec 16, 2023 14:43:38 GMT
Function LoadDrives$ (drives() As String) If InStr(_OS$, "[WINDOWS]") Then Shell _Hide Chr$(34) + "wmic logicaldisk get name" + Chr$(34) + ">TempDirList.txt" ReDim drivess(0) As String
Open "TempDirList.txt" For Input As #1 Line Input #1, junk$ 'First line is name counter = 0 Do Until EOF(1) counter = counter + 1 Input #1, junk$ 'drive name ReDim _Preserve drivess(counter) As String If Len(junk$) > 1 Then junk$ = Mid$(junk$, 2, 1) + ":" Else junk$ = "": counter = counter - 1 If junk$ <> "" Then drivess(counter) = junk$ End If Loop Close #1 Kill "TempDirList.txt"
For manual = 1 To counter LoadDrives$ = LoadDrives$ + Left$(drivess(manual), 1) Next End If End Function
Anyways this is the problem I am having with the LoadDrives = LoadDrives(drivess(manual),1) statement , can it be reworded ina way that it will do the same and not bomb in the compiler?
|
|
|
Post by bplus on Dec 16, 2023 16:06:32 GMT
Since version 2.0 you can not use the function name to build a string even though that string will be the function assignment when done, so I used rtn$ to use a temp string to finally assign function it's value when done assuming we are in Windows... ReDim d$(0) Print LoadDrives$(d$()) ' <<< returns CD for my system For i = LBound(d$) To UBound(d$) Print i, d$(i) ' <<< nothing? for me and my system Next
Function LoadDrives$ (drives() As String) Dim rtn$ If InStr(_OS$, "[WINDOWS]") Then Shell _Hide Chr$(34) + "wmic logicaldisk get name" + Chr$(34) + ">TempDirList.txt" ReDim drivess(0) As String
Open "TempDirList.txt" For Input As #1 Line Input #1, junk$ 'First line is name counter = 0 Do Until EOF(1) counter = counter + 1 Input #1, junk$ 'drive name ReDim _Preserve drivess(0 To counter) As String If Len(junk$) > 1 Then junk$ = Mid$(junk$, 2, 1) + ":" Else junk$ = "": counter = counter - 1 If junk$ <> "" Then drivess(counter) = junk$ End If Loop Close #1 Kill "TempDirList.txt"
For manual = 1 To counter rtn$ = rtn$ + Left$(drivess(manual), 1) Next LoadDrives$ = rtn$ End If End Function
Welcome to the forum rcamp48
|
|