As String would be a single line of text, what would be the variable type for multiple lines of text?
Printable View
As String would be a single line of text, what would be the variable type for multiple lines of text?
You can store many lines in a string
This isn't true... A string is a string, it doesn't matter how many lines it contains. You can add lines to a string by inserting Chr(10), Chr(13), ControlChars.NewLine... Some thing lke this:Quote:
Originally Posted by smart_phil_dude1
VB Code:
Dim str As String = "This is 1st line" & Chr(10) & "This is 2nd line"
Well, a string is really just an array of chars and a new line is just a combination of chars, so thus you can have any number of "lines" in a string variable.
well, i am programming an application that reads off multiple lines on a txt file, but it won't read multiple lines, it only works if one line is written.
How do you read the file? And what version of VB are you coding with?Quote:
Originally Posted by smart_phil_dude1
If you are reading one line at a time then you're only reading part of the string that the file contains at a time. You can read the whole file into a single string:or you can read the contents of the file and break it up on the line breaks:VB Code:
Dim contents As String = IO.File.ReadAllText("file path here")There are other ways to read the file too but they all amount to the same thing. You can read the whole file into a single string if you want. If you read a line at a time then it's YOU who are removing the line breaks and splitting the file contents into pieces. If you don't need the individual lines then don't break the file up into lines. If you do need the lines then you can either read and use one line at a time or do as I did above and use a String array.VB Code:
Dim lines As String() = IO.File.ReadAllLines("file path here")
i set it up into different lines, just like using your second example...
Sorry, I'm not sure whether that last post constituted a question or not.
well i tried what you explained and i still get an error
And how can we possibly help fix it if you don't tell us what it is?