|
-
Jan 23rd, 2007, 12:00 AM
#1
Thread Starter
Fanatic Member
[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?
Last edited by Slyke; Jan 23rd, 2007 at 10:13 AM.
-
Jan 23rd, 2007, 12:13 AM
#2
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, "")
-
Jan 23rd, 2007, 12:19 AM
#3
Thread Starter
Fanatic Member
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?
-
Jan 23rd, 2007, 05:54 AM
#4
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
-
Jan 23rd, 2007, 06:33 AM
#5
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
-
Jan 23rd, 2007, 10:12 AM
#6
Thread Starter
Fanatic Member
Re: Multiline File into a single line string.
-
Jan 23rd, 2007, 11:54 AM
#7
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|