Help - Search - Members - Calendar
Full Version: Visual Basic OpenDialog Problem
Pixel2Life Forum > Help Section > Desktop Programming
Nightscream
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 happy.gif

thanks in advance smile.gif

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
Mezzo
QUOTE(Nightscream @ Aug 10 2007, 10:44 AM) *
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 happy.gif

thanks in advance smile.gif

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


Try putting New in there
CODE
Dim myStream As New Stream

Nightscream
Ok i have done
CODE
Dim myStream As IO.Stream

It works in visual basic itself(express edition) but it doesn't work in access
it doesn't know IO.Stream
and when I try to do
CODE
Imports SYSTEM.IO

It doesn't know Imports.
How can i fix this.
It works in Visual studio but not in access.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.