Virtual drive

D

daniel chen

Hi, Dave
I couldn't find any difference with either X: or x: in any combination
within any test macro I have below.
The resultant NUL/nul depends on the last statement used -- TestStr =
Dir("X:\NUL") / TestStr = Dir("X:\nul") respectively.
The drawback is they cannot be used in a unified way -- not even with
<Application.Run "********">.
It toggled on and off. Any comment will be appreciated.
(My target cell : C:\R_D\[ABC.xls]sheet1!A1 with phrase "Virtual Drive
Assignment Test" )

Sub auto_open()
Dim TestStr As String
TestStr = ""
On Error Resume Next
TestStr = Dir("X:\NUL")
On Error GoTo 0
If TestStr = "" Then
Shell Environ("comspec") & " /c subst x: " _
& Chr(34) & "C:\R_D" & Chr(34), vbHide
End If
Cells(2, 1) = TestStr
End Sub

Sub auto_close()
On Error Resume Next
TestStr = Dir("x:\nul")
On Error GoTo 0
If TestStr = "nul" Then
Shell Environ("comspec") & " /c subst X: /d "
End If
' Note: It became unpredictable when I added the following statements.
' If TestStr = "" Then
' Shell Environ("comspec") & " /c subst X: /d "
' End If
End Sub

Sub TroubleShoot()
TestStr = Dir("X:\nul")
Cells(2, 1) = TestStr
' Cells(2, 1) = Dir("X:\nul")
End Sub

Sub DevTest()
Cells(3, 1) = ""
Application.Run "auto_open"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "='X:\[ABC.xls]Sheet1'!R1C1"
Application.Run "auto_close"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Cells(3, 1) = "Thru"
End Sub
 
D

daniel chen

Ooop, with one exception -- the 2 nuls in Sub auto_close must be of the
same case level, but independent what is in Sub auto_open.

daniel chen said:
Hi, Dave
I couldn't find any difference with either X: or x: in any combination
within any test macro I have below.
The resultant NUL/nul depends on the last statement used -- TestStr =
Dir("X:\NUL") / TestStr = Dir("X:\nul") respectively.
The drawback is they cannot be used in a unified way -- not even with
<Application.Run "********">.
It toggled on and off. Any comment will be appreciated.
(My target cell : C:\R_D\[ABC.xls]sheet1!A1 with phrase "Virtual Drive
Assignment Test" )

Sub auto_open()
Dim TestStr As String
TestStr = ""
On Error Resume Next
TestStr = Dir("X:\NUL")
On Error GoTo 0
If TestStr = "" Then
Shell Environ("comspec") & " /c subst x: " _
& Chr(34) & "C:\R_D" & Chr(34), vbHide
End If
Cells(2, 1) = TestStr
End Sub

Sub auto_close()
On Error Resume Next
TestStr = Dir("x:\nul")
On Error GoTo 0
If TestStr = "nul" Then
Shell Environ("comspec") & " /c subst X: /d "
End If
' Note: It became unpredictable when I added the following statements.
' If TestStr = "" Then
' Shell Environ("comspec") & " /c subst X: /d "
' End If
End Sub

Sub TroubleShoot()
TestStr = Dir("X:\nul")
Cells(2, 1) = TestStr
' Cells(2, 1) = Dir("X:\nul")
End Sub

Sub DevTest()
Cells(3, 1) = ""
Application.Run "auto_open"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "='X:\[ABC.xls]Sheet1'!R1C1"
Application.Run "auto_close"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Cells(3, 1) = "Thru"
End Sub

Dave Peterson said:
That sounds backwards to me.

dir("x:\nul") will return NUL if that drive letter exists. Then you use Subst
again.

And watchout for undeclared variables (Dim's are your friend).

And watchout for upper/lower case problems. nul <> NUL.

Dave Peterson
(e-mail address removed)
 
D

Dave Peterson

This is the line that I was warning about:

If TestStr = "nul" Then

If teststr returned "NUL", then it wouldn't match "nul".

So you could check a couple of different ways:

Option Compare Text
at the top of your module will treat upper/lower/mixed the same.

if lcase(teststr) = lcase("NuL") then
would make do it, too.

Inside the dir("x:\nul"), you could use any variation.

(I thought checking dir() = "" would be easier to do.)




daniel said:
Hi, Dave
I couldn't find any difference with either X: or x: in any combination
within any test macro I have below.
The resultant NUL/nul depends on the last statement used -- TestStr =
Dir("X:\NUL") / TestStr = Dir("X:\nul") respectively.
The drawback is they cannot be used in a unified way -- not even with
<Application.Run "********">.
It toggled on and off. Any comment will be appreciated.
(My target cell : C:\R_D\[ABC.xls]sheet1!A1 with phrase "Virtual Drive
Assignment Test" )

Sub auto_open()
Dim TestStr As String
TestStr = ""
On Error Resume Next
TestStr = Dir("X:\NUL")
On Error GoTo 0
If TestStr = "" Then
Shell Environ("comspec") & " /c subst x: " _
& Chr(34) & "C:\R_D" & Chr(34), vbHide
End If
Cells(2, 1) = TestStr
End Sub

Sub auto_close()
On Error Resume Next
TestStr = Dir("x:\nul")
On Error GoTo 0
If TestStr = "nul" Then
Shell Environ("comspec") & " /c subst X: /d "
End If
' Note: It became unpredictable when I added the following statements.
' If TestStr = "" Then
' Shell Environ("comspec") & " /c subst X: /d "
' End If
End Sub

Sub TroubleShoot()
TestStr = Dir("X:\nul")
Cells(2, 1) = TestStr
' Cells(2, 1) = Dir("X:\nul")
End Sub

Sub DevTest()
Cells(3, 1) = ""
Application.Run "auto_open"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "='X:\[ABC.xls]Sheet1'!R1C1"
Application.Run "auto_close"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Cells(3, 1) = "Thru"
End Sub

Dave Peterson said:
That sounds backwards to me.

dir("x:\nul") will return NUL if that drive letter exists. Then you use Subst
again.

And watchout for undeclared variables (Dim's are your friend).

And watchout for upper/lower case problems. nul <> NUL.

Dave Peterson
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top