Start New Discussion within our Software Development Community

Hi All,
Does anyone know why I'm getting a 'Null Reference' error when I try to use a FolderBrowser?

I have the following code (called from a Toolstrip Menu Item):

<code>
Dim fldBrowser As FolderBrowserDialog = New FolderBrowserDialog
fldBrowser.RootFolder = Environment.SpecialFolder.DesktopDirectory
fldBrowser.Description = "Which Folder do you want to use as a Destination?"
If fldBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then
strSelection = fldBrowser.SelectedPath
End If
fldBrowser = Nothing
</code>

This works perfectly well in one project, but not my new one :(

The 'Help' suggests using the "New" keyword, so which part of '= New FolderBrowserDialog' doesn't it understand?

Please save my computer from an untimely demise...

Thanks for looking,

Chris.

Ok, so it seems it's important to type out (and not Copy/Paste as I did).

I've just rewritten the function in the new project (word for word - it's identical) and now it works - go figure.

Maybe VB just has problems with Pasted Code?

Thanks for looking.

This question has already been answered. Start a new discussion instead.