|
-
Apr 19th, 2001, 01:10 AM
#1
Thread Starter
New Member
when the program writes to the text file, the data continues to be written horizontally instead of writing to a newline.
here's the code i am using:
Open App.Path & "\data.txt" For Append As #1
For i = 0 To 8
Write #1, txtField(i).Text,
Next i
Close #1
eg: data.txt
"132456","R.","Kelly","1","2","3","4","5","6","987654","Michael","Jordan","6","5","4","3","2","1",et c..
want:
"132456","R.","Kelly","1","2","3","4","5","6" (without comma at the end)
"987654","Michael","Jordan","6","5","4","3","2","1"
etc..
would anyone know how to make it move to newline?
thanks.
-
Apr 19th, 2001, 01:59 AM
#2
When using write() I don't think you will be able to create a new line, since write() doesn't support this.
You would therefore have to swicth to another way of writing to the file.
If you just want this structure you could write:
dim strTmp as string
dim i as byte
Open App.path & "\data.txt" for Append as #1
For i=0 to 8
strTmp = chr(34) & txtField(i).Text & Chr(34) & chr(44)
Next i
strTmp = Left(StrTmp, len(StrTmp)-1) & chr(13) & chr(10)
Print #1, strTmp
Close #1
I think this should do it, however I havn't tested it.
-
Apr 19th, 2001, 07:18 AM
#3
Thread Starter
New Member
o.k
o.k i'll give it a try.
thanks.
-
Apr 19th, 2001, 07:29 AM
#4
Lively Member
Surely you can just do this? 
Code:
Open App.Path & "\data.txt" For Append As #1
For i = 0 To 8
Write #1, txtField(i).Text & vbCrLf,
Next i
Close #1
-
Apr 19th, 2001, 08:14 AM
#5
Retired VBF Adm1nistrator
I only ever use output like follows :
Code:
Print #1, something
if thats of any help
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 19th, 2001, 10:01 AM
#6
Thread Starter
New Member
o.k thanks guys.
o.k here are the outputs.
AIS_DK: your method writes the last piece of information and two new lines.
"(txtField(8).text"
_
_
m0rph: your method writes the information then a newline and in my text boxes there are funny looking squares on the end of the fields.
"(txtField(1).text
","(txtField(2).text
","(txtField(3).text
","(txtField(4).text
plenderj: i might play around with Print #1 too.
thanks guys...
-
Apr 19th, 2001, 10:17 AM
#7
Ok my mistake, I wasn't near my computer with VB on, so here is little fix up.
Print ofcourse terminates any string that you write with a new line, so the correct code should be:
dim strTmp as string
dim i as byte
Open App.path & "\data.txt" for Append as #1
For i=0 to 8
strTmp = strTmp & chr(34) & txtField(i).Text & Chr(34) & chr(44)
Next i
strTmp = Left(StrTmp, len(StrTmp)-1)
Print #1, strTmp
strTmp = ""
Close #1
See if that should not fix it
BTW. Funny looking Squares are mearly characters, that either has no visual "face" or can't be shown by the program you use. IE. If your text reader doesn't interpret TAB, then the program would display the "character" TAB with a square.
-
Apr 19th, 2001, 10:30 AM
#8
Retired VBF Adm1nistrator
Dont be sad you maggot, just use Print 
Code:
Dim i As Long
For i = 0 to txtField.Count -1
Print #1, txtField(i).Text
Next i
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 19th, 2001, 10:32 AM
#9
maybe instead of VBCRLF, just use either VBCR or VBLF.
(Try both, not sure which would do it)
-
Apr 21st, 2001, 03:22 PM
#10
Thread Starter
New Member
thanks
thanks guys for your help, most of the help posted produced what i wanted in the end.
thanks.
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
|