Sinisterly
VB - Import Text From .txt file? -- Help! - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: VB - Import Text From .txt file? -- Help! (/Thread-VB-Import-Text-From-txt-file-Help)



VB - Import Text From .txt file? -- Help! - Morpheus_mybb_import11112 - 03-20-2013

Hey guys, just 2 quick questions.

1. This is quite hard to explain, but I am making a program and for my project, there could be a ton of text coding involved. But I want to just import it fro ma text document to make life a lot easier. Like so:

Code:
TextBox.Text = "get text here line 1"
  TextBox.Text = "get text here line 2"
  TextBox.Text = "get text here line 3"
  TextBox.Text = "get text here line 4"
  TextBox.Text = "get text here line 5"
  TextBox.Text = "get text here line 6"
  TextBox.Text = "get text here line 7"
  TextBox.Text = "get text here line 8"
  TextBox.Text = "get text here line 9"
  TextBox.Text = "get text here line 10"

Now, is there a way to get information from a text document, added to my program, on each line, to fill in for each "my text here line #"?
Confusing, but here's a picture to explain:
[Image: IA1YZIW.png]

So import the text from the text document for each line, into where it would go in the VB script. If you are still unsure, then reply a question and I'll try to answer my best. It really hard to explain what I'm trying to get haha.

**

2. Now for this program, I was wondering if I have my finished project and the text document in the same folder. The program uses the text document in the source code to run properly. If I crypt that text document and bind it to my finished program, will it run correctly? This may be a stupid question, but it seems to me that my program wouldn't be able to read the text document's information if it is crypted. I'm not trying to hide anything, it just makes it a hell of a lot easier than typing out all of the code into the VB form when I could just import it.

Let me know! Thanks,

-Kevin


RE: VB - Import Text From .txt file? -- Help! - ArkPhaze - 03-21-2013

You would never assign to:
Code:
TextBox.Text

So is this all the same TextBox or a bunch of different TextBoxes?

If it's all the same use File.ReadAllText() to copy the string over to the control. If it is different TextBoxes, I would index from File.ReadAllLines().

Might look something like this...
Code:
Dim lines As String() = File.ReadAllLines("FILEPATH")
For i As Integer = 0 To lines.Length - 1
    Me.Controls("TextBox" + i.ToString()).Text = lines(i)
Next



RE: VB - Import Text From .txt file? -- Help! - ddee - 03-21-2013

Just use a File Reader to grab your text. After this, if I understand your clue you need to manipulate each line. So, go on like this:
Code:
Do Until yourSTRING Is Nothing
  yourSTRING = FILEREADER.ReadLine()
Loop
Replace yourSTRING with a list or whatever control (with the appropriate code change) you like to store the info. If you need further assistance just ask for it.


RE: VB - Import Text From .txt file? -- Help! - ArkPhaze - 03-21-2013

(03-21-2013, 09:43 AM)ddee Wrote: Just use a File Reader to grab your text. After this, if I understand your clue you need to manipulate each line. So, go on like this:
Code:
Do Until yourSTRING Is Nothing
  yourSTRING = FILEREADER.ReadLine()
Loop
Replace yourSTRING with a list or whatever control (with the appropriate code change) you like to store the info. If you need further assistance just ask for it.

I think you mean StreamReader, not FileReader.


RE: VB - Import Text From .txt file? -- Help! - ddee - 03-21-2013

Quote:I think you mean StreamReader, not FileReader.

That is right! Wink