Results 1 to 9 of 9

Thread: Strange error - splitting and adding to listview

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Strange error - splitting and adding to listview

    hi,

    friends i don't no how to fix, so here's me code:
    Code:
    For Each ln In IO.File.ReadAllLines(iniFile)
                If ln.ToLower.StartsWith("app name") Then
                    Dim app_name As String = ln.Substring(ln.IndexOf(":"c) + 1) '//a faster and more efficient option than splitting
                End If
    
                App_List.Items.Add(app_name)
    
            Next
    on this line: App_List.Items.Add(app_name) it says app_name is not declared....

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Strange error - splitting and adding to listview

    The problem is that you're declaring app_name inside the If .... End If statement. That means it only exist inside that code block so directly after the End If it doesn't exist anymore but there is where you're trying to add it to the App_List.Items. Even if it existed outside the If block it wouldn't have contain any value if the If statement evaluates to false. Move the App_List.Items.Add line to be inside the If block.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Strange error - splitting and adding to listview

    Yea I thought of doing that but i'm wanting to add another Else If to get the exe with the same method, then i can get a icon from the exe........

    Then do App_List.Items.Add(icon, app_name)

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Strange error - splitting and adding to listview

    So you thought of doing it the way it works but you thought you'd just carry on the way it doesn't? Is that supposed to make sense to anyone?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Strange error - splitting and adding to listview

    Well yea, if i move: App_list.items.add(app_name) to inside the IF, then grab the exe: ElseIf ln.ToLower.StartsWith("app file") Then
    dim Exe as string = ln.Substring(ln.IndexOf(":"c) + 1) , then convert to icon.....

    so how to add: icon, app_name as 1 item?

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Strange error - splitting and adding to listview

    Well you don't. Not in that way. The image must be added to the ListView images list and then either the item's Image Key or Index property set to associate the image. So it's at least a two step process, assuming the image is already registered, or three if not.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Strange error - splitting and adding to listview

    I don't understand what you're trying to do. What is the layout of your file? Maybe you need to read in more information from the file before you even add an item to the list?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Strange error - splitting and adding to listview

    Code:
    app name:app v1
    app file: blah\.......\....\.........\app.exe
    this is my .ini file........

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Strange error - splitting and adding to listview

    You can capture the different headers like this:-
    vbnet Code:
    1. '
    2.         For Each ln In IO.File.ReadAllLines(iniFile)
    3.             Dim app_name As String
    4.             Dim file_name As String
    5.  
    6.  
    7.             If ln.ToLower.StartsWith("app name") Then
    8.                 app_name = ln.Substring(ln.IndexOf(":"c) + 1)
    9.                 Continue For
    10.             End If
    11.  
    12.             If ln.ToLower.StartsWith("app file") Then
    13.                 file_name = ln.Substring(ln.IndexOf(":"c) + 1)
    14.             End If
    15.  
    16.  
    17.             ''''You may add to your list here
    18.            
    19.  
    20.         Next
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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