[Resolved] Multiline File into a single line string.
This problem always keep comming up. When reading from a file that has multiple lines during debug (though i only need the first line), the program works fine. But when compiled and trying to read from it, the it somtimes reads the first line as null and i have to make code that will read the second line. In notepad it says it's the first line.
VB Code:
Open Filename For Input As #1
Line Input #1, File_Contents
Close #1
^^^^^ Code used.
Any way, what i want to know is how to load the entire file contents into a string. No matter how many lines or what ever else.
If i had this stored in a file:
QWERTY
ASDFGH
ZXCVBN
and loaded it, i want it to look like this in a string "QWERTYASDFGHZXCVBN"
Can anyone help me out?
Re: Multiline File into a single line string.
Dim strStream As String
Open Filename For Input As #filenumber
strStream = Input(LOF(filenumber), #filenumber)
strStream = Replace(strStream, Chr(0), "")
strStream = Replace(strStream, vbCrLF, "")
Re: Multiline File into a single line string.
Thanks dude!
VB Code:
Dim strStream As String
Open Filename For Input As #1
strStream = Input(LOF(1), #1)
strStream = Replace(strStream, Chr(0), "")
strStream = Replace(strStream, vbCrLF, "")
Close #1
This correct?
Re: Multiline File into a single line string.
VB Code:
Private Sub Command1_Click()
Dim filename As String
filename = App.Path & "\List.txt"
Open filename For Input As #1
Text1.Text = Input(LOF(1), #1)
Text1.Text = Replace(Text1.Text, Chr(0), "")
Text1.Text = Replace(Text1.Text, vbCrLf, "")
Close #1
End Sub
I done this and it worked perfectly no errors well unless the file isn't their but im sure you would know what to do then :)
Re: Multiline File into a single line string.
VB Code:
Private Sub Command1_Click()
Dim filename As String
filename = App.Path & "\Listview.txt"
Open filename For Input As #1
Text1.Text = Input(LOF(1), #1)
Text1.Text = Replace(Text1.Text, Chr(0), "")
Text1.Text = Replace(Text1.Text, vbCrLf, "")
Text1.Text = Replace(Text1.Text, Space$(number here), "")
Close #1
End Sub
This will put spaces in between each line. Set the integer to what you want :D
Re: Multiline File into a single line string.
Re: [Resolved] Multiline File into a single line string.
Thanks for letting us know that you have your answer. The next time you may find it easier by just pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.