Jump to content


Photo

Visual Basic OpenDialog Problem


  • Please log in to reply
2 replies to this topic

#1 Nightscream

Nightscream

    Young Padawan

  • Members
  • Pip
  • 100 posts
  • Gender:Male
  • Location:Belgium

Posted 10 August 2007 - 09: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 :biggrin:

thanks in advance :)

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


#2 Mezzo

Mezzo

    Young Padawan

  • Members
  • Pip
  • 102 posts
  • Gender:Male
  • Location:Toronto Ontario

Posted 10 August 2007 - 10:21 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 :biggrin:

thanks in advance :)

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
Dim myStream As New Stream


#3 Nightscream

Nightscream

    Young Padawan

  • Members
  • Pip
  • 100 posts
  • Gender:Male
  • Location:Belgium

Posted 13 August 2007 - 07:22 AM

Ok i have done
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
Imports SYSTEM.IO
It doesn't know Imports.
How can i fix this.
It works in Visual studio but not in access.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users