FileDialog question

Hi

As if I don't have enough problems!

I copied the routine below from the help system into my code.

Straight away, then item DialogResult complained that :

'Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated'

Is there something there that I should be doing to correct this error

This is an unaltered copy from the help system.

Private Sub button1_Click(sender As Object, e As System.EventArgs)
Dim myStream As Stream
Dim openFileDialog1 As New OpenFileDialog()

openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then
myStream = openFileDialog1.OpenFile()
If Not (myStream Is Nothing) Then
' Insert code to read the stream here.
myStream.Close()
End If
End If
End Sub




Answer this question

FileDialog question

  • Sherley Lee

    When you see that message and hover the cursor over it you will see a little red exclamation mark click on it.

    It will give you the suggestion to correct it.

    Dim myStream As System.IO.Stream
    Dim openFileDialog1 As New OpenFileDialog()

    openFileDialog1.InitialDirectory = "c:\"
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    openFileDialog1.FilterIndex = 2
    openFileDialog1.RestoreDirectory = True

    If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    myStream = openFileDialog1.OpenFile()
    If Not (myStream Is Nothing) Then
    ' Insert code to read the stream here.
    myStream.Close()
    End If
    End If


  • TimFells

    Trying to troubleshoot from my last post is driving me crazy.

    Even just this plain small block has exactly the same error. The DialogResult.OK gives the error as per last post.

    Dim Result As DialogResult

    Result = DialogResult.OK



  • Pranky

    Thank you. That fixed it.

    But why on earth does the help system not just show that! It's as hard trying to learn the help system as it is to learn coding



  • FileDialog question