groone
asked on
Whats wrong with this? - ListView/Text File
Okay, here is some code I am having trouble with.
The first part creates a nice comma delimited file with 9 variables recieved from a ListView. It works very nice. The problem is the latter part of the code. The program is suppose to open and then load the list into the listview. The problem is that it stops at the
With li
.SubItem(1) = putVar_2
and goes no further, there are no error messages or anything, simply stops. I know this is something really super easy that I am overlooking.
Here is my code. This is a learning tool for me, so the names of forms HAVE NOT been changed to protect the innocent. Please pay attention to the putInList function for this is the one I am having problems with. Thanks...and no, I do not know how to use type's yet ;p
Function checkFile()
Dim FileExists
On Error Resume Next
Open App.Path & "list.dat" For Input As #1
Close #1
FileExists = Not (Err <> 0)
If FileExists = False Then
fileDoesntExistMakeIt
Else
fileExistsOpen
End If
End Function
Function fileDoesntExistMakeIt()
Open App.Path & "list.dat" For Output As #1
Close #1
End Function
Function writeToTheFile()
Dim curItem, numberOfItems As Integer
Dim li As ListView
Open App.Path & "list.dat" For Output As #1
Set li = Form1.ListView1
With li
numberOfItems = .ListItems.Count
While curItem < numberOfItems
DoEvents
curItem = curItem + 1
Write #1, .ListItems.Item(curItem), .ListItems.Item(curItem).S ubItems(1) , .ListItems.Item(curItem).S ubItems(2) , .ListItems.Item(curItem).S ubItems(3) , .ListItems.Item(curItem).S ubItems(4) , .ListItems.Item(curItem).S ubItems(5) , .ListItems.Item(curItem).S ubItems(6) , .ListItems.Item(curItem).S ubItems(7) , .ListItems.Item(curItem).S ubItems(8)
Wend
End With
Close #1
End Function
Function fileExistsOpen()
Dim var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9
Open App.Path & "list.dat" For Input As #1
Do While Not EOF(1)
DoEvents
Input #1, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9
putInList var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9
Loop
Close #1
End Function
Function putInList(putVar_1, putVar_2, putVar3, putVar_4, putVar_5, putVar_6, putVar_7, putVar_8, putVar_9)
Dim li As ListItem
Set li = Form1.ListView1.ListItems. Add(, putVar_1, putVar_1)
With li
.SubItems(1) = putVar_2
.SubItems(2) = putVar_3
.SubItems(3) = putVar_4
.SubItems(4) = putVar_5
.SubItems(5) = putVar_6
.SubItems(6) = putVar_7
.SubItems(7) = putVar_8
.SubItems(8) = putVar_9
End With
End Function
The first part creates a nice comma delimited file with 9 variables recieved from a ListView. It works very nice. The problem is the latter part of the code. The program is suppose to open and then load the list into the listview. The problem is that it stops at the
With li
.SubItem(1) = putVar_2
and goes no further, there are no error messages or anything, simply stops. I know this is something really super easy that I am overlooking.
Here is my code. This is a learning tool for me, so the names of forms HAVE NOT been changed to protect the innocent. Please pay attention to the putInList function for this is the one I am having problems with. Thanks...and no, I do not know how to use type's yet ;p
Function checkFile()
Dim FileExists
On Error Resume Next
Open App.Path & "list.dat" For Input As #1
Close #1
FileExists = Not (Err <> 0)
If FileExists = False Then
fileDoesntExistMakeIt
Else
fileExistsOpen
End If
End Function
Function fileDoesntExistMakeIt()
Open App.Path & "list.dat" For Output As #1
Close #1
End Function
Function writeToTheFile()
Dim curItem, numberOfItems As Integer
Dim li As ListView
Open App.Path & "list.dat" For Output As #1
Set li = Form1.ListView1
With li
numberOfItems = .ListItems.Count
While curItem < numberOfItems
DoEvents
curItem = curItem + 1
Write #1, .ListItems.Item(curItem), .ListItems.Item(curItem).S
Wend
End With
Close #1
End Function
Function fileExistsOpen()
Dim var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9
Open App.Path & "list.dat" For Input As #1
Do While Not EOF(1)
DoEvents
Input #1, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9
putInList var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9
Loop
Close #1
End Function
Function putInList(putVar_1, putVar_2, putVar3, putVar_4, putVar_5, putVar_6, putVar_7, putVar_8, putVar_9)
Dim li As ListItem
Set li = Form1.ListView1.ListItems.
With li
.SubItems(1) = putVar_2
.SubItems(2) = putVar_3
.SubItems(3) = putVar_4
.SubItems(4) = putVar_5
.SubItems(5) = putVar_6
.SubItems(6) = putVar_7
.SubItems(7) = putVar_8
.SubItems(8) = putVar_9
End With
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also . . you did not get any errors because of the on error resume next statement in the calling sub/procedure
ASKER
I cannot seem to find the .ListSubItems object anywhere.
I set the listview
dim li as listitem
'we assume key is set already
set li = Form1.ListView1.ListItems. Add(putVar _1)
with li
.ListSubItems.Add , putVar_2, putVar2 'doesnt work
'listsubitems is nonexistent
end with
What am I doing wrong?
I set the listview
dim li as listitem
'we assume key is set already
set li = Form1.ListView1.ListItems.
with li
.ListSubItems.Add , putVar_2, putVar2 'doesnt work
'listsubitems is nonexistent
end with
What am I doing wrong?
What version of vb are you using?? Can you use .subitems.add?
ASKER
nevermind. I was using common controls 5.0 rather than 6.0. It works now. THanks
ASKER