I click a button open dialog displays, I select my file it displays in text box now I want to use tha selected file so i can stream write all contents to a text file when I click btn 2
here is the code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Text Files To Transfer"
OpenFileDialog1.InitialDirectory = "C:temp"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim strm As System.IO.Stream
strm = OpenFileDialog1.OpenFile()
txtbox.Text = OpenFileDialog1.FileName.ToString()
If Not (strm Is Nothing) Then
'insert code to read the file data
strm.Close()
MessageBox.Show("Are You Ready To Transfer")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim RandomNumber As New Random()
Dim Tr As IO.TextReader = System.IO.File.OpenText("C:\Users\spritchard\Desktop\Bom\test.txt")
Dim FileLines() As String = Split(Tr.ReadToEnd(), vbCrLf)
Tr.Close()
Dim Textfile As String = FileLines(RandomNumber.Next(0, UBound(FileLines)))
MsgBox(Textfile)
End Sub
End Class
here is the code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Text Files To Transfer"
OpenFileDialog1.InitialDirectory = "C:temp"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim strm As System.IO.Stream
strm = OpenFileDialog1.OpenFile()
txtbox.Text = OpenFileDialog1.FileName.ToString()
If Not (strm Is Nothing) Then
'insert code to read the file data
strm.Close()
MessageBox.Show("Are You Ready To Transfer")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim RandomNumber As New Random()
Dim Tr As IO.TextReader = System.IO.File.OpenText("C:\Users\spritchard\Desktop\Bom\test.txt")
Dim FileLines() As String = Split(Tr.ReadToEnd(), vbCrLf)
Tr.Close()
Dim Textfile As String = FileLines(RandomNumber.Next(0, UBound(FileLines)))
MsgBox(Textfile)
End Sub
End Class