-
Oct 31st, 2007, 01:38 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] writing text file
i'm stuck on this, maybe someone could offer some insight. I am creating a text file like this. it works just as it should.
Code:
Write #1, CStr(SeqNumber); rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
my problem is i have a combo box that the user can enter in text. i want to loop through the number of list items entered in the combo box (which i have saved in an array) and add them to the beginning of the text line above.
-
Oct 31st, 2007, 01:41 PM
#2
Re: writing text file
This will save the entire contents of the Combo. Is that what you are after?
Code:
Dim i As Long
Open "c:\ComboBox.txt" For Output As #1
For i = 0 To Combo1.ListCount - 1
Combo1.ListIndex = i
Print #1, Combo1.List(Combo1.ListIndex)
Next
Close #1
End Sub
-
Oct 31st, 2007, 01:58 PM
#3
Thread Starter
Fanatic Member
Re: writing text file
write #1, text1; text2
if user adds item to combo box then
write #1 combotext1; text1; text2
but what if user adds 5 items to combo box? how can i loop through combo and add each entry to begining of the line?
-
Oct 31st, 2007, 02:01 PM
#4
Re: writing text file
Hack gave you the code to iterate through the combobox items.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Oct 31st, 2007, 02:04 PM
#5
Thread Starter
Fanatic Member
Re: writing text file
how do i write the item to the beginning of the line of text that already exists? thats my problem.
-
Oct 31st, 2007, 03:03 PM
#6
Lively Member
Re: writing text file
If you're trying to insert the combo text before the other text, couldn't you string together the combo box items first and then print, something like this?
Code:
dim i as long
dim holdstring as string
for i = 0 to combo1.count -1
holdstring = holdstring & combo1.list(i) & ";"
next
Then do your print stmt...
Code:
Open "c:\ComboBox.txt" For Output As #1
Print #1, holdstring & "any other text you want to print after"
Close #1
-
Oct 31st, 2007, 03:12 PM
#7
Re: writing text file
Code:
Dim i As Long
Open "c:\ComboBox.txt" For Output As #1
For i = 0 To Combo1.ListCount - 1
Combo1.ListIndex = i
Print #1, Combo1.List(Combo1.ListIndex)
Next
Write #1, CStr(SeqNumber); rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
Close #1
End Sub
Print will save the text (contents of the line in the ComboBox, in this case) as it is.
Write will save it with commas between items and quotes around each string item.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Oct 31st, 2007, 03:50 PM
#8
Thread Starter
Fanatic Member
Re: writing text file
i need it all on the same line. i'm creating a comma delimited text file. each combo item must be enclosed in quotation marks and separated by a comma. that is why i'm using the write function.
-
Oct 31st, 2007, 04:41 PM
#9
Re: writing text file
Just a slight change
Code:
Dim i As Long
Open "c:\ComboBox.txt" For Output As #1
For i = 0 To Combo1.ListCount - 1
Combo1.ListIndex = i
Write #1, Chr$(34);Combo1.List(Combo1.ListIndex);Chr$(34);",";
Next
Write #1, CStr(SeqNumber); rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
Close #1
End Sub
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Nov 1st, 2007, 09:06 AM
#10
Thread Starter
Fanatic Member
Re: writing text file
thanks for the help. turns out you don't have to add your own quotes or commas, the write function does it for you. just make sure to use the semi colon. this is how i did it (i saved the combo into an array):
Code:
For y = 0 To UBound(TagLineArray) - 1
Write #1, TagLineArray(y);
Next y
Write #1, rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
Close #1
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
|