Question Writing text from .txt file to a textbox

tstory28

New member
Joined
Oct 3, 2011
Messages
2
Location
Topeka, Kansas, United States
Programming Experience
Beginner
I am almost done with writing a program for my nephew and am stuck on trying to input text from a file into a textbox for statistical viewing. I have searched all over the internet and not yet found anything that works.

Here is what I am trying to do.

MathQuiz.txt

Date/Time You got ? questions out of 20 questions correct!
Date/Time You got ? questions out of 20 questions correct!

I need the "Date/Time You got ? questions out of 20 questions correct!" to be copied from the txt file and inserted into a Rich Textbox named rtbStats.

Thanks for any help provided.
 
The most likely reason that you haven't found anything on the web is the fact that you're looking for a ready-made solution to a multi-part problem. Think about it. How is text handled in VB.NET? With String objects, right? So, you need to get a String from a file and then display a String in a RichTextBox. If you read anything about a RichTextBox then it should be fairly easy to find out how to display a String. The MSDN documentation for the class should be your first thought, but I'm sure there is plenty of other helpful information on the web. You probably don't even need any of that anyway though. I'm fairly sure that you wouldn't have got this far without knowing how to display text in a control. Have you ever displayed text in a Label, Button or TextBox? If so then you know how to display text in a RichTextBox because it's done the very same way.

As for reading text from a file, I know from previous experience that it's a 20 second job to find information on the web on how to do that.

read text file vb.net - Google Search

There are various ways to implement the specifics and you just have to determine the one that best suits your app.
 
You can try this command..

Dim vFileText As String
vFileText = "d:\MathQuiz.txt"
Dim vObj As New System.IO.StreamReader(vFileText)
RichTextBox1.Text = vObj.ReadToEnd


hopefully help:smile:
 
Back
Top