We help IT Professionals succeed at work.
Get Started

Whats wrong with this? - ListView/Text File

groone asked
Last Modified: 2010-05-02
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
    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
                curItem = curItem + 1
                Write #1, .ListItems.Item(curItem), .ListItems.Item(curItem).SubItems(1), .ListItems.Item(curItem).SubItems(2), .ListItems.Item(curItem).SubItems(3), .ListItems.Item(curItem).SubItems(4), .ListItems.Item(curItem).SubItems(5), .ListItems.Item(curItem).SubItems(6), .ListItems.Item(curItem).SubItems(7), .ListItems.Item(curItem).SubItems(8)
        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)
            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
    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
Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE