a1338noob

Hey, i need to know how to access a text file, then display it in a Rich Text Box one word at a time using a timer interval. I got the timer part down, i just need to know how to access a text file and then how to pick through it and display the first word then the second then the third, then the forth, then the fifth, and then the sixth and then the seventh and then the eighth and then the ninth and then the tenth. :)


Re: Visual Basic Express Edition accessing Text Files

a1338noob

I did find out how to make it say something in the text box over and over using the timer, however, i was not able to find out how to import the text file. Should i just put it as a string




Re: Visual Basic Express Edition accessing Text Files

a1338noob

Alright, here is my code, the line that i am having an error with is marked.
<Microsoft.VisualBasic.ComClass()> Public Class Form1
Dim i As Integer
Dim fso, ts
Const ForWriting = 2
Dim s As String
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
i = i + 1
RichTextBox1.Text = ts.read(5) '<----------------------------- ThIs OnE!1!1!
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
fso = CreateObject("Scripting.FileSystemObject")
ts = fso.OpenTextFile("C:\Documents and Settings\Jake\Desktop\SpeedReader\white.txt", ForWriting, True)
End Sub
End Class




Re: Visual Basic Express Edition accessing Text Files

JohnWein

If you want to read from the file why do you open it for writing

Edit:  Why are you using visual basic script  

Edit:  Here's some visual basic express code that might do what you want:

Public Class Form1< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

  Private FileName As String = _

    "C:\Documents and Settings\Jake\Desktop\SpeedReader\white.txt"

  Private FileReader As System.IO.StreamReader

  Private Sub Form1_Load(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles Me.Load

    Dim FileWriter As System.IO.StreamWriter

    FileWriter = My.Computer.FileSystem.OpenTextFileWriter(FileName, False)

    Dim I As Integer

    For I = 0 To 9

      FileWriter.WriteLine("Word" + CStr(I))

    Next I

    FileWriter.Close()

    FileWriter.Dispose()

    FileReader = My.Computer.FileSystem.OpenTextFileReader(FileName)

    Timer1.Enabled = True

  End Sub

  Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) _

    Handles Timer1.Tick

    Timer1.Enabled = False

    RichTextBox1.AppendText(FileReader.ReadLine + Chr(13) + Chr(10))

    If FileReader.EndOfStream Then

      FileReader.Close()

      FileReader.Dispose()

      Exit Sub

    End If

    Timer1.Enabled = True

  End Sub

End Class





Re: Visual Basic Express Edition accessing Text Files

a1338noob

IDK, some tutorial told me to do that. If i try "ForReading" it gives me an error.




Re: Visual Basic Express Edition accessing Text Files

AtomZ .be

dim sr as system.io.streamreader = new system.io.streamreader("<path to file>")
richtextbox1.text=sr.read()

Grtz, Tom.






Re: Visual Basic Express Edition accessing Text Files

a1338noob

Thank you so much! that did the trick.