Results 1 to 3 of 3

Thread: Index out of bounds after loading from file

  1. #1
    bsmfs
    Guest

    Index out of bounds after loading from file

    I have a wierd problem with a ListView in report mode.
    Basically Im dragging and dropping Items from a TreeView into a ListView, which works without a problem.

    I can save the listview contents to a file, Im using a simple ini type file.
    I can re-load the contents of the file back into the listview without no trouble, All information is placed in columns correctly.

    However..the code at the very bottom will only work if the listview contents were not loaded from a file, If I load contents from a file I get Index out of bounds message every time.

    Heres the open from Ini type file code (Seems to work Fine)
    Code:
    IdCount2 = 0
    M = 0
    C = 0
    Value = IniString("IconIndex 10", "List10 Count", OpenFileName)
    txtINI.Text = Value
    'MsgBox txtINI
    If txtINI.Text = App.Path & "\" & OpenFileName Then
    GoTo IconIndex11
    Exit Sub
    End If
    
    M = Value
    
    'Icon Index 10 loop
    Do
    C = C + 1
    IdCount2 = IdCount2 + 1
    
    Value = IniString("IconIndex 10", "Item " & IdCount2, OpenFileName)
    txtINI.Text = Value
    
    With ListView1
    .Icons = imgDirTree
    .ListItems.Add (C), "_10_" & txtINI, txtINI, , 10
    .ListItems(C).SubItems(1) = "All *.* "
    Value = IniString("IconIndex 10", "Size " & IdCount2, OpenFileName)
    txtINI.Text = Value
    .ListItems(C).SubItems(2) = txtINI
    End With
    
    Loop Until C = M
    GoTo IconIndex11
    Exit Sub
    Im trying to read info back from the ListView here. this code works if i do not load from a file.
    Code:
    C = 0
    M = frmBackUp.ListView1.ListItems.Count
    
    Do
    C = C + 1
    With frmBackUp.ListView1.ListItems
    L = Left(.Item(C).Key, 4) 'grab the key and strip the 1st 4 chars to determine the Icon Numbers
    
    'A few other grab info lines here.
    
    End With
    Loop Until C = M
    Does anybody know why this wont work after being reloaded from a file?
    No matter what I do the index is always out of bounds, even though the variable 'C' has the correct value (In This Case 1).

    Thanks in advance for any help!

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Are you sure its crashing when C=1?

    See if this format works better:
    VB Code:
    1. While C <> M
    2. C = C + 1
    3. With frmBackUp.ListView1.ListItems
    4. L = Left(.Item(C).Key, 4) 'grab the key and strip the 1st 4 chars to determine the Icon Numbers
    5.  
    6. 'A few other grab info lines here.
    7.  
    8. End With
    9. Wend
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    bsmfs
    Guest
    Thanks for the reply.

    I just tried your much better looking code crptcblade but it still gave the index out of bounds message.

    The listview acts as if its empty, that is the only thing i can think of that would give an out of bounds error on the 1st item..1

    C does = 1 (A messagebox confirmed this)

    if i enter
    frmBackUp.ListView1.ListItems(C) 'crashes on this line
    it should return item number 1 in the list but seems its returning nothing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width