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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.