J
Jerry West
I am new to VB .NET moving from VB6. I wrote the following code and as a
result I received an error concerning it from the IDE. I don't understand
why I get the message or why that what I am doing is not legal. Here is the
code:
Public Function mP_IsPathExist(ByVal Path As String) As Boolean
On Error Resume Next
Dim myIO As New System.IO.FileInfo(Path)
If (Not myIO.Exists()) Then Dim myIO As New
System.IO.DirectoryInfo(Path)
Return myIO.Exists()
End Function
The error message flags the second Dim statement for myIO. It states:
Variable 'myIO' hides a variable in an enclosing block
I get the sense I cannot reuse the var myIO. Do I have to declare a
completely new var for initializing the DirectoryInfo structure? And what
"enclosing block" does it refer to? The function itself?
Thanks for any insight!
JW
result I received an error concerning it from the IDE. I don't understand
why I get the message or why that what I am doing is not legal. Here is the
code:
Public Function mP_IsPathExist(ByVal Path As String) As Boolean
On Error Resume Next
Dim myIO As New System.IO.FileInfo(Path)
If (Not myIO.Exists()) Then Dim myIO As New
System.IO.DirectoryInfo(Path)
Return myIO.Exists()
End Function
The error message flags the second Dim statement for myIO. It states:
Variable 'myIO' hides a variable in an enclosing block
I get the sense I cannot reuse the var myIO. Do I have to declare a
completely new var for initializing the DirectoryInfo structure? And what
"enclosing block" does it refer to? The function itself?
Thanks for any insight!
JW