Results 1 to 23 of 23

Thread: [VERY URGENT!]Debug This Code![PLEASE]

  1. #1

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Angry [VERY URGENT!]Debug This Code![PLEASE]

    I need some help with this script. It's not working....

    VB Code:
    1. Private Sub LoadFavorites()
    2.         'Set up the treeview
    3.         tvFavorites.Nodes.Clear()
    4.         tvFavorites.Nodes.Add("Favorites")
    5.         tvFavorites.Nodes(0).ImageIndex = 10
    6.         tvFavorites.Nodes(0).SelectedImageIndex = 10
    7.  
    8.         Dim FavPath() As String
    9.         Dim strsplit() As String
    10.         Dim strFav As String
    11.         Dim i As Short
    12.         Dim oNode As TreeNode
    13.         Try
    14.             'Load Folders from Favorites Root
    15.             FavPath = Directory.GetDirectories(GetFolderPath(SpecialFolder.Favorites))
    16.             For Each strFav In FavPath
    17.                 oNode = New TreeNode
    18.                 strsplit = Split(strFav, "\", , CompareMethod.Text)
    19.                 i = UBound(strsplit)
    20.                 oNode.ImageIndex = 18
    21.                 oNode.SelectedImageIndex = 19
    22.                 oNode.Text = strsplit(i)
    23.                 oNode.Tag = strFav
    24.                 tvFavorites.Nodes(0).Nodes.Add(oNode)
    25.                 LoadSubFolders(oNode, strFav)
    26.             Next
    27.  
    28.             FavPath = Directory.GetFiles(GetFolderPath(SpecialFolder.Favorites))
    29.             For Each strFav In FavPath
    30.                 If InStr(strFav, ".ini", CompareMethod.Text) Then
    31.  
    32.                 Else
    33.                     oNode = New TreeNode
    34.                     Dim oFile As New FileInfo(strFav)
    35.                     strsplit = Split(oFile.Name, ".url", , CompareMethod.Text)
    36.                     oNode.Text = strsplit(0)
    37.                     oNode.ImageIndex = 16
    38.                     oNode.SelectedImageIndex = 16
    39.                     oNode.Tag = GetUrl(strFav)
    40.                     tvFavorites.Nodes(0).Nodes.Add(oNode)
    41.                 End If
    42.             Next
    43.         Catch ex As Exception
    44.         Catch ex As DirectoryNotFoundException
    45.         Catch ex As IO.IOException
    46.         End Try
    47.         oNode = Nothing
    48.     End Sub

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Where is the error at?? We need more info.. what line?

  3. #3

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    With the tvFavorites.Nodes and the GetFolderPath.

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Im guessing this is code you found?? You first need a treeview control on your form, called tvFavorites...

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    FavPath = Directory.GetDirectories(GetFolderPath(SpecialFolder.Favorites))

    Nowhere do you have specialfolder.favorites defined... and the directory is not declared..

    Directory example...
    VB Code:
    1. Dim MyDirectory As New System.IO.DirectoryInfo("Directory path")
    After you declare your directory, THEN you can call .GetDirectories, and .GetFiles..

  6. #6

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    I have a treeview named that. It's the nodes thats messing it up.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Jeez...what is the error?!
    "Make it idiot-proof and someone will make a better idiot"

  8. #8
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    I just copied a treeview in my form, and ran the following code:
    VB Code:
    1. 'in button click
    2.         LoadFavorites()
    3.        
    4.         'sub in form
    5.         Private Sub LoadFavorites()
    6.         'Set up the treeview
    7.         tvFavorites.Nodes.Clear()
    8.         tvFavorites.Nodes.Add("Favorites")
    9.         tvFavorites.Nodes(0).ImageIndex = 10
    10.         tvFavorites.Nodes(0).SelectedImageIndex = 10
    11.         End Sub
    All worked fine... I repeat.. are you SURE you have a treeview control NAMED tvFavorites in the SAME form you are calling the LoadFavorites sub from?

  9. #9
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    And here is your code I modified on my machine, currently it loads what is in my "c:\" directory and adds them to the listbox... There were other things not shown in your code, that wern't defined, or defined elsewhere... (certain lines are commented out for a reason, in order to post a working example...)
    VB Code:
    1. Private Sub LoadFavorites()
    2.         'Set up the treeview
    3.         tvFavorites.Nodes.Clear()
    4.         tvFavorites.Nodes.Add("Favorites")
    5.         tvFavorites.Nodes(0).ImageIndex = 10
    6.         tvFavorites.Nodes(0).SelectedImageIndex = 10
    7.  
    8.         Dim FavPath() As String
    9.         Dim strsplit() As String
    10.         Dim strFav As String
    11.         Dim i As Integer
    12.         Dim oNode As TreeNode
    13.         Dim MyDirectory As System.IO.Directory
    14.  
    15.         Try
    16.             'Load Folders from Favorites Root
    17.             FavPath = MyDirectory.GetDirectories("C:\")
    18.             For Each strFav In FavPath
    19.                 oNode = New TreeNode()
    20.                 strsplit = Split(strFav, "\", , CompareMethod.Text)
    21.                 i = UBound(strsplit)
    22.                 oNode.ImageIndex = 18
    23.                 oNode.SelectedImageIndex = 19
    24.                 oNode.Text = strsplit(i)
    25.                 oNode.Tag = strFav
    26.                 tvFavorites.Nodes(0).Nodes.Add(oNode)
    27.                 'LoadSubFolders(oNode, strFav)
    28.             Next
    29.  
    30.             FavPath = MyDirectory.GetFiles("C:\")
    31.             For Each strFav In FavPath
    32.                 If InStr(strFav, ".ini", CompareMethod.Text) = 1 Then
    33.  
    34.                 Else
    35.                     oNode = New TreeNode()
    36.                     Dim oFile As New System.IO.FileInfo(strFav)
    37.                     strsplit = Split(oFile.Name, ".url", , CompareMethod.Text)
    38.                     oNode.Text = strsplit(0)
    39.                     oNode.ImageIndex = 16
    40.                     oNode.SelectedImageIndex = 16
    41.                     'oNode.Tag = GetUrl(strFav)
    42.                     tvFavorites.Nodes(0).Nodes.Add(oNode)
    43.                 End If
    44.             Next
    45.         Catch ex As Exception
    46.             'Catch ex As DirectoryNotFoundException
    47.         Catch ex As IO.IOException
    48.         End Try
    49.         oNode = Nothing
    50. End Sub

  10. #10

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Nice...thanks a bunch. However, it's still having trouble with the tvFavorites.Nodes

  11. #11
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    what is the error? Tough to fix if we dont know.

  12. #12

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    'Nodes' is not a member of 'System.Windows.Forms.ListView'.

  13. #13
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Why are you calling the node property in listview? Listview has no node property only treeview has it.

  14. #14

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Im not too sure. It was just in the example i found. Any way around it?

  15. #15
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Once again... you need to have a TREEVIEW... not a LISTVIEW named tvFavorites.....
    If you ADD A TREEVIEW instead of a LISTVIEW it will WORK! lol.. don't know how many times we have to say it...

    Notice in the comments in the code...
    VB Code:
    1. 'Set up the Treeview

  16. #16

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Ok mr.fancy pants. Debug this one.
    If Not CurNode.Tag = Nothing Then
    Process.Start(CurNode.Tag)
    End If

  17. #17

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    CurNode is not declared.

  18. #18
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Though not in your previous code, the "Tag" is an option for each item of the treeview. They are simply running then current node's tag (a variable they declared) in a Process.Start command...
    Example.....
    VB Code:
    1. Dim CurNode As TreeNode
    2. CurNode.Tag = tvFavorites.Nodes(0).Tag

  19. #19

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    OK then. So
    VB Code:
    1. Dim CurNode As  TreeNode
    2. CurNode.Tag = tvfavorites.Nodes(0) .Tag
    will do the same as the messed up code that i had?

  20. #20
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    No, not sure what they are putting as a tag.. the code above doesn't add a tag to the treeview items, so you would get an error.

  21. #21

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    What would be a treeview tag?

  22. #22

    Thread Starter
    Banned
    Join Date
    Oct 2005
    Posts
    73

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    Anyone?

  23. #23
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [VERY URGENT!]Debug This Code![PLEASE]

    if you give us a description of what you are trying to accomplish exactly, we can try to give you better suggestions... I'm not sure where this tag code popped up, and why you are trying to use it, as it was not in your original post...

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