Ok I know how to write to a file using append and output....however how about if I wanted to write to a certine line in a file. For example How would i write off to line 1 and on to line 2?
Printable View
Ok I know how to write to a file using append and output....however how about if I wanted to write to a certine line in a file. For example How would i write off to line 1 and on to line 2?
I'm most likely wrong...
but i think it's something like:
So you would maily need the "Line Input #1, Text1"Code:blah = 0
Open "hosts.txt" For Input As #1
Do Until EOF(1)
blah = blah + 1
If blah = 1 Then Line Input #1, somevar$: Text1 = Text1 & somevar$
If blah = 2 Then Line Input #1, somevar$: Text2 = Text2 & somevar$
If blah = 3 Then Line Input #1, somevar$: Text3 = Text3 & somevar$: blah = 0
Hope that helped,
D!m
You can write a blank line using vbNewLine. Although, that line will still be considered a variable.
Code:Open "MyFile.txt" For Output As #1
Write #1, vbNewLine, "2nd Line"
Close #1
Thanks a lot, I just did it the long way. There where six different things instead of putting them in 6 different lines i used 6 different text files since thats how I knew how to do it.
This is how i did it to add lines to autoexec.bat file,but it works the same for .txt files.
Option Explicit
Dim Message As String, Message1 As String
Dim Message2 As String
Form_Load
Message = "What?"
Message1 = "Huh?"
Message2 = "Yeah"
Open "c:\windows\whatever.txt" For Append As #1
Print #1, Message
Close #1
Open "c:\windows\whatever.txt" For Append As #2
Print #2, Message1
Close#2
Open "c:\windows\whatever.txt" For Append As #3
Print #3, Message2
Close #3
End Sub
I am sure there is a better way to do this ,but at the moment i dont know how to do it any other way...
Later
NewBEE Vbeer6.0()
"Gopher this Gopher that"
End Sub