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....
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.
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)
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?
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?
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.
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?
Re: Strange error - splitting and adding to listview
Code:
app name:app v1
app file: blah\.......\....\.........\app.exe
this is my .ini file........
Re: Strange error - splitting and adding to listview
You can capture the different headers like this:-
vbnet Code:
'
For Each ln In IO.File.ReadAllLines(iniFile)
Dim app_name As String
Dim file_name As String
If ln.ToLower.StartsWith("app name") Then
app_name = ln.Substring(ln.IndexOf(":"c) + 1)
Continue For
End If
If ln.ToLower.StartsWith("app file") Then
file_name = ln.Substring(ln.IndexOf(":"c) + 1)
End If
''''You may add to your list here
Next