Need help with several things about text files
Okay. lets say in a text file, i have:
10/10/10, 11/12/13, 10/20/21,
all on one line. how can i get it to do the following:
1)Seperate each date and put it into a listbox
2)Seperate each date and put it into a variable
I am stuck... Please help. Also, is there a way in vb6 to export several listboxes to a spreadsheet file? if so, how? Thanks!
Re: Need help with several things about text files
Try this:
vb Code:
Private Sub Command1_Click()
Dim str As String
Dim i As Integer
Dim entry As String
ff = FreeFile
Open App.Path & "\test.txt" For Input As #ff
For i = 0 To Len(ff) + 1
Input #ff, entry
List1.AddItem entry
str = entry
Next i
MsgBox (str)
Close #ff
End Sub
Re: Need help with several things about text files
o.o What the heck... Okay. I want multiple entries... Not just one.. Like if i had multiple dates... And on top of that, have no idea what that codes does... Well.. Have some idea. What does the Len(ff) do?
Re: Need help with several things about text files
Quote:
Originally Posted by
Gamemaster1494
o.o What the heck... Okay. I want multiple entries... Not just one.. Like if i had multiple dates... And on top of that, have no idea what that codes does... Well.. Have some idea. What does the Len(ff) do?
Have you tested the code? It works with multiple entries! The len(ff) is the maximum number of entries in the file.
Edit:
To change the number of entries that appear, change the 1 to a different number. Say you have 30 entries in the file change the number "1" to "29". This value is the iteration value for the for cycle meaning how many times do you want it to run.
Re: Need help with several things about text files
Yeah. it works... now how can i make it do that at certain entries? Like if the txt file had:
Jacob
Pouring
Noway
10/10/10, 10/11/10, 10/12/10,
OkayIGetIt
Only have it to do it at line 4? and do something else for the others?
Re: Need help with several things about text files
You could add this code just before the next.
vb Code:
If i = 4 Then
List1.AddItem entry
str = entry
End If
Re: Need help with several things about text files
Okay. So what code is it that separates it?
Re: Need help with several things about text files
The conditional statement checks to see which value of entry you you want to add to the list box and if the value matches it adds it to the list box.
Re: Need help with several things about text files
um... okay.... Hmmm.... So... How would i get it to where like the txt file says:
10/10/10, 21/10/10, 21/11/10
for example. and i want
variable(1) = 10/10/10, variable(2) = 21/10/10, variable(3) = 21/11/10
Is there a way to do that?
Re: Need help with several things about text files
Try this:
vb Code:
Private Sub Command1_Click()
Dim x As Integer
Dim sInputArr() As String
Dim i As Integer
Dim a As Integer
Dim entry As String
ff = FreeFile
Open App.Path & "\test.txt" For Input As #ff
For i = 0 To Len(ff) + 5
Input #ff, entry
If i = 3 Or i = 4 Or i = 5 Then
List1.AddItem entry
'Split up the String into the Array
If InStr(entry, ",") Then 'More than 1 word, so split
sInputArr = Split(entry, ",")
Else
ReDim sInputArr(i) 'Only 1 word, so place it in the Array
sInputArr(i) = entry
MsgBox (sInputArr(i))
End If
End If
Next i
Close #ff
End Sub