Values from a Listbox as subclass of a class Listbox

  1. 4 months ago

    This is a request of help. I am trying to adapt the example Project "FileBrowser" and I am stranded at the first move (saving to a file the listbox rows reporting the contents of a disk). I see that the list box is dealt with as a subclass of a class Listbox (VolumeBrowserList, and I don't exactly understand what's the advantage of this choice: someone would be patient and explain it to me?): the worst is that the only value I can get is FileList.name; any other attempt to get a value (i.e. FileList.cell(1,1) or even FileList.HasHeading) leads to a compilation error "Method or property not existing". Of course I am missing something big with classes and subclasses... Any Help? Thanks

    Thank you, Tim! It works. Sorry for my delayed post

  2. Roger C

    Jan 27 Lewis Center, OH

    Here is an example project which wasn't well tested. There is a naming conflict. Note the MainMenuBar-UntitledMenu2 has an item named FileList. Thus the compiler is confused with the conflict between this menuItem and the instance of VolumeBrowserList.
    Change the name of the instance of VolumeBrowserList on the window to xFileList (or anything else except FileList) and xFileList.hasHeading will work fine.

    The reason for creating a subclass of listbox to use here is a) for demonstration purposes and b) it's good OOP to encapsulate the specific functions which have been added to this listbox subclass. To use those add'l functions in your own project, just export the VolumeBrowserList to your project.

    HTH

  3. Thank you so much for your quick, clear and exhaustive answer!

  4. 3 months ago

    Here again. It worked smoothly... except one situation I met today: I have a USB disk connected to a Time capsule (quite old).
    When the item in the listbox is referred to this disk, double clicking leads to a list of voices but generates the error
    "An exception of class NilObjectException was not handled. The application must shut down."
    The instruction where the condition is encountered is >>>>

    For i As Integer = 1 To f.Count
    >>>> If f.TrueItem(i).Visible Then
    If f.TrueItem(i).Directory = True Then //Checks if the file is a folder
    Me.AddFolder(f.TrueItem(i).Name) //This adds a new folder to the list
    Else
    Me.Addrow(f.TrueItem(i).Name) //Lines like this add a row to the listbox, which stand for a file in the folder being viewed
    End If
    etc

    Any suggestion? Thanks

  5. Roger C

    Feb 12 Lewis Center, OH

    You're not checking for f = Nil

    For i As Integer = 1 To f.Count
    if f <> Nil Then
    >>>> If f.TrueItem(i).Visible Then
  6. Thank you for your suggestion. I already tried... f is not Nil, but the exception happens anyway... It seems the expression TrueItem is responsible when the disk is connected to the computer not directly (USB on the Mac) but via TimeCapsule->wiFi->Mac.

  7. writing the line
    Exception o As NilObjectException
    at the end of the method, it seems to work correctly, but I get no error code...
    I would like to know what happens...

  8. Tim H

    Feb 12 Pre-Release Testers Portland, OR USA

    Unravel that line. It is possible TrueItem can return nil. So use an intermediate value to test it.

    truef = f.TrueItem(i)
    if truef <> Nil then
        if truef.visible then 
  9. Thank you, Tim! It works. Sorry for my delayed post

or Sign Up to reply!