Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to stream write a selcted file chosen in open dialog

Status
Not open for further replies.

Shaun29

Programmer
Oct 22, 2008
53
US
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
 
Your code don't seem to be VBA, so I guess you've posted in a wrong forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top