G
Guest
I have written a method that should modify the folder path passed to it into one that exists and is selected by the user. It then returns a boolean depending on whether a folder path was selected by the user
It then dawned on me that I was passing in a readonly property into the method yet neither at compile time or runtime was I getting any kind of error or warning.
I tested with a simple string field and it alter the string as expected but with a readonly property when it leaves the method the injected property remains unaffected but surprisingly no error is generated to indicate that an attempt have been made to assign a new value to a readonly property
Maybe the compiler should smell a rat with a readonly property being passed into a method byRef, I don't know, but certainly I would expect a runtime error of some kind. Has anyone else encounterd this 'feature'
'code snippit..
dim corrected as Boolea
Dim myDirInfo As IO.DirectoryInfo = New IO.DirectoryInfo( "???" ) 'pathname name of a non existant folder
corrected = GetFolderPath(inDirInfo.FullName) 'as expected fullname doesn't change but no kind of error is raised either
'method code..
Public Function GetFolderPath(ByRef inSelectedPath As String) As Boolea
Dim dialog As New Windows.Forms.FolderBrowserDialo
Dim dr As DialogResul
Dim okayed As Boolean = Fals
dialog.Description = "The following import folder does not exist: " & vbCrLf & inSelectedPath & vbCrLf & vbCrLf & "Please select a valid folder path...
Dim folderPart As String = inSelectedPat
While Not System.IO.Directory.Exists(folderPart) AndAlso folderPart <> "
folderPart = IO.Directory.GetParent(folderPart).FullNam
End Whil
dialog.ShowNewFolderButton = Fals
dialog.SelectedPath = folderPar
okayed = dialog.ShowDialog() = DialogResult.O
If okayed The
'-----------------------
inSelectedPath = dialog.SelectedPath 'this is the assignment that should cause problems either here or upon the method return, but it doesn't
'-----------------------
End I
dialog.Dispose(
Return okaye
End Function
It then dawned on me that I was passing in a readonly property into the method yet neither at compile time or runtime was I getting any kind of error or warning.
I tested with a simple string field and it alter the string as expected but with a readonly property when it leaves the method the injected property remains unaffected but surprisingly no error is generated to indicate that an attempt have been made to assign a new value to a readonly property
Maybe the compiler should smell a rat with a readonly property being passed into a method byRef, I don't know, but certainly I would expect a runtime error of some kind. Has anyone else encounterd this 'feature'
'code snippit..
dim corrected as Boolea
Dim myDirInfo As IO.DirectoryInfo = New IO.DirectoryInfo( "???" ) 'pathname name of a non existant folder
corrected = GetFolderPath(inDirInfo.FullName) 'as expected fullname doesn't change but no kind of error is raised either
'method code..
Public Function GetFolderPath(ByRef inSelectedPath As String) As Boolea
Dim dialog As New Windows.Forms.FolderBrowserDialo
Dim dr As DialogResul
Dim okayed As Boolean = Fals
dialog.Description = "The following import folder does not exist: " & vbCrLf & inSelectedPath & vbCrLf & vbCrLf & "Please select a valid folder path...
Dim folderPart As String = inSelectedPat
While Not System.IO.Directory.Exists(folderPart) AndAlso folderPart <> "
folderPart = IO.Directory.GetParent(folderPart).FullNam
End Whil
dialog.ShowNewFolderButton = Fals
dialog.SelectedPath = folderPar
okayed = dialog.ShowDialog() = DialogResult.O
If okayed The
'-----------------------
inSelectedPath = dialog.SelectedPath 'this is the assignment that should cause problems either here or upon the method return, but it doesn't
'-----------------------
End I
dialog.Dispose(
Return okaye
End Function