|
-
Dec 4th, 2007, 07:37 PM
#1
Thread Starter
Junior Member
[2005] open file dialog problem
I am trying to use the open dialog to allow the user to select the file being computed. I think my code is right, but visual basic says that 'type stream has not been defined'.
Any help is appreciated. Code below.
champ0342
Code:
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myStream As Stream = Nothing
Dim ofd As New OpenFileDialog()
ofd.InitialDirectory = "c:\"
ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
If ofd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = ofd.OpenFile()
If (myStream IsNot Nothing) Then
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Try another file)
Finally
If (myStream IsNot Nothing) Then
End If
End Try
End If
End Sub
-
Dec 4th, 2007, 07:41 PM
#2
New Member
Re: [2005] open file dialog problem
Dim fileStream As System.IO.FileStream = Nothing
try that
-
Dec 4th, 2007, 07:45 PM
#3
Thread Starter
Junior Member
Re: [2005] open file dialog problem
Thanks. That kinda did it, but I had to change one part:
Code:
Dim fileStream As System.IO.Stream = Nothing
by making it system.io.stream instead of system.io.filestream it works under option strict.
-
Dec 4th, 2007, 07:46 PM
#4
Frenzied Member
Re: [2005] open file dialog problem
try this
Code:
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ofd As New OpenFileDialog()
Dim MyValue As String = ""
ofd.InitialDirectory = "c:\"
ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
If ofd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Using sr As New StreamReader(ofd.FileName)
MyValue = sr.ReadToEnd()
End Using
End If
End Sub
That should work, and if the file is not found
use ofd.CheckFilePath, or a property with a similar name which checks the file exists...
-
Dec 4th, 2007, 07:55 PM
#5
Thread Starter
Junior Member
Re: [2005] open file dialog problem
A new challenger approaches.....
when it opens the file it gives me an error says that ' the system cannot find the file .../bin/debug/system.io.filestream'
does anyone know what that error means?
-
Dec 4th, 2007, 07:58 PM
#6
New Member
Re: [2005] open file dialog problem
think its HAS TO BE
system.io.FILESTREAM
and not system.io.stream
since you will be using all the funcitons that deals with FILES.
-
Dec 4th, 2007, 07:58 PM
#7
Frenzied Member
Re: [2005] open file dialog problem
Sorry, I forgot to mention, you need to do this at the top of your code (above everything)
Imports System.IO
or change the streamreader code to
Code:
Using sr As New System.IO.StreamReader(ofd.FileName)
MyValue = sr.ReadToEnd()
End Using
-
Dec 4th, 2007, 08:29 PM
#8
Thread Starter
Junior Member
Re: [2005] open file dialog problem
I need to split the line into two sections. How do I do that. I tried this code:
Code:
MyValue = sr.ReadLine.Split
but it said that: "value of a 1d array can not be converted to a string".
-
Dec 4th, 2007, 08:35 PM
#9
Frenzied Member
Re: [2005] open file dialog problem
Declare MyValue As An Array
Dim MyValue() As String
MyValue = sr.ReadLine.Split()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|