View Single Post
08-10-2007, 02:53 PM
#1
Nightscream is offline Nightscream
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 0 / 0%
 

Nightscream is on a distinguished road

  Old  Visual Basic OpenFileDialog problem

I got a problem with a visual basic script to get OpenFileDialog, to browse a filename
but always getting errors at the second line, something with As Stream.
Maybe you can fix this problem ^_^
(it's in access)

thanks in advance

Code:
Private Sub Bladeren_Click()
Dim myStream As Stream = Nothing
    
    Dim openFileDialog1 As New OpenFileDialog()

    openFileDialog1.InitialDirectory = "N:\"
    openFileDialog1.Filter = "All files (*.*)|*.*"
    openFileDialog1.FilterIndex = 1
    openFileDialog1.RestoreDirectory = True

    If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        Try
            myStream = openFileDialog1.OpenFile()
            If (myStream IsNot Nothing) Then
                ' Insert code to read the stream here.
                Voorbeeld = myStream
            End If
        Catch Ex As Exception
            MessageBox.Show ("Cannot read file from disk. Original error: " & Ex.Message)
        Finally
            ' Check this again, since we need to make sure we didn't throw an exception on open.
            If (myStream IsNot Nothing) Then
                myStream.Close()
            End If
        End Try
    End If
    
End Sub