0

Hello guys.

I'am trying to make my search program, so that i can load a text file and search it.

I used this code for browsing and opening

Dim streamer As IO.StreamReader

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        OpenFileDialog1.ShowDialog()
        TextBox1.Text = OpenFileDialog1.FileName
        streamer = IO.File.OpenText(TextBox1.Text)
        Dim mystring() As String = streamer.ReadToEnd.Split(vbNewLine)
        ListBox1.Items.AddRange(mystring)
    End Sub

So this will browse for text file and when I open it, this text file should appear in listbox.

But when I click browse i get a dialog box. If I click cancel this error appears:

System.ArgumentException: Empty path name is not legal.

And one more question how to delete path of my text file. Because when I add it, path appears in textbox.

3
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by Jx_Man
Featured Replies
  • 3

    You can check file name length.. [CODE]Dim streamer As IO.StreamReader Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click OpenFileDialog1.ShowDialog() If OpenFileDialog1.FileName.Length > 0 Then TextBox1.Text = OpenFileDialog1.FileName streamer = IO.File.OpenText(TextBox1.Text) Dim mystring() As String = streamer.ReadToEnd.Split(vbNewLine) ListBox1.Items.AddRange(mystring) End If End Sub[/CODE] Read More

  • you could set the visible property of the textbox to False or probably more simply just declare a local variable to hold the string [CODE] dim FileToOpen as String FileToOpen = OpenFileDialog1.FileName [/CODE] Read More

0

you need to check whether the text box contains anything before you attempt to open it. After line 6 put an if statement

if textbox1.text <> "" then

and after line 9

end if
3

You can check file name length..

Dim streamer As IO.StreamReader
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    OpenFileDialog1.ShowDialog()
    If OpenFileDialog1.FileName.Length > 0 Then
        TextBox1.Text = OpenFileDialog1.FileName
        streamer = IO.File.OpenText(TextBox1.Text)
        Dim mystring() As String = streamer.ReadToEnd.Split(vbNewLine)
        ListBox1.Items.AddRange(mystring)
    End If
End Sub

Edited by Jx_Man: n/a

Comments
As always
Thx Jx
1

you could set the visible property of the textbox to False or probably more simply just declare a local variable to hold the string

dim FileToOpen as String
FileToOpen = OpenFileDialog1.FileName
Comments
You also helped me. Thx
0

you could set the visible property of the textbox to False or probably more simply just declare a local variable to hold the string

dim FileToOpen as String
FileToOpen = OpenFileDialog1.FileName

That textbox is for searching :)

I added at the end of line

TextBox1.Text = ""

Thx guys.

I hope you do not mind the constant questions. I am still a beginner :(

0

>> I hope you do not mind the constant questions. I am still a beginner
Its okay.. Enjoy Daniweb :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.