[RESOLVED] Can't seem to use my Public Sub.
Greetings. I'm trying to write a little sub routine that will update a listview. I've got several list views and different controls that will write to them so the sub needs to be quite flexible, here is my code:
Code:
Public Sub UpdateListView(ListViewName As String, ListViewItem As Long, ListViewColumn As Long, ControlData As String)
ListViewName.ListItems(ListViewItem).SubItems(ListViewColumn) = ControlDate
End Sub
I've not worked with ListViews much so there may be errors in the way I am populating it, but that's okay - I'll cross that hurdle when I get to it, my actual problem is when I call this sub i.e.
Code:
updatelistview("frmcompanydetails.lvwBankDetails", frmcompanydetails.lvwBankDetails.SelectedItem.index, 0, frmcompanydetails.txtAccountName.Text)
The line has somthing wrong with it, it shows up red :| I've had a good look through and can't see any obvious syntax errors.
Any ideas?
Re: Can't seem to use my Public Sub.
Why do you have double quotes around the first parameter?
Either both strings would need them, not just one, or neither one would need them.
Re: Can't seem to use my Public Sub.
just remove the brackets after updateListview
vb Code:
UpdateListView "frmcompanydetails.lvwBankDetails", frmcompanydetails.lvwBankDetails.SelectedItem.Index, 0, frmcompanydetails.txtAccountName.Text
or add Call before updateListview
PHP Code:
Call UpdateListView("frmcompanydetails.lvwBankDetails", frmcompanydetails.lvwBankDetails.SelectedItem.Index, 0, frmcompanydetails.txtAccountName.Text)
Re: Can't seem to use my Public Sub.
Ok I see a couple errors
First of all take "frmcompanydetails.lvwBankDetails" out of quotes. Second, columns start at 1 not 0 so you will also get an error there. Other than that without testing it. It seems to check out.
Re: Can't seem to use my Public Sub.
frmcompanydetails.lvwBankDetails is in quotes because I wish to pass that as a string, not a value that it holds, otherwise it would be frmcompanydetails.lvwBankDetails.Name or similar. Does that make sense?
I'll change it from 0 to 1 also for the first column, thanks for pointing that out ;)
Re: Can't seem to use my Public Sub.
was post #3 of no help? :sob:
Re: Can't seem to use my Public Sub.
By looking at your function I can tell you that what you are doing wont work. If you pass the listview as a string it will treat it as a string. Take it out of quotes and then your function wont do this. I also just saw another error. You are populating incorrectly. You need to populate your listview as so:
Sub Items
Code:
ListViewName.ListItems(ListViewItem).SubItems(ListViewColumn).add ,, ControlDate
Main Items
Code:
ListViewName.ListItems.add ,, ControlDate
Re: Can't seem to use my Public Sub.
Yep, I took the brackets off, works perfectly thankyou :)
I was looking for
Code:
Public Sub UpdateListView(byref ListViewName As ListView...
Also, subitem(1) is updating the second column, but subitem(0) is just crashing. I guess it's because the first column is not a subitem, I can fix this myself though. Thanks for all the help!
Re: Can't seem to use my Public Sub.
That is correct. The first item is accessed via the ListView's Text property.
All remaining items/columns are accessed via SubItem.
Re: Can't seem to use my Public Sub.
Quote:
ListViewName.ListItems.add ,, ControlDate
I've kept my method and it is working fine!
Code:
UpdateListView frmCompanyDetails.lvwBankDetails, frmCompanyDetails.lvwBankDetails.SelectedItem.Index, 1, frmCompanyDetails.txtBankName.Text
Public Sub UpdateListView(ByRef ListViewName As ListView, ListViewItem As Long, ListViewColumn As Long, ControlData As String)
ListViewName.ListItems(ListViewItem).SubItems(ListViewColumn) = ControlData
End Sub
Re: Can't seem to use my Public Sub.
Don't forget, if you consider this resolved, you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you. :)
Re: Can't seem to use my Public Sub.
Thanks for the hint Hack :) I was just going to give it a bit of a test run before marking it as resolved, so that I don't have to make a new thread if anything was broken. As it turns out, seems to work just fine, now I just need to put in the criteria of it being the first column or not. I might just go ahead and hard code the first column updates - 5 hours straight codemonkeying has taken it out of me :|
Re: [RESOLVED] Can't seem to use my Public Sub.
Oh I see you wish only to change the text of the sub item. Hmm, ok, I guess you code is satisfactory for that.
Edit: You could always just give an option in the function to say if it is a subitem or a main item. Hang on I'll whip something up.
Edit 2: Here is a quick addon to your function that just requires you to specify if it is a sub item or not. 0 for main column, 1 for sub item.
Code:
Public Sub UpdateListView(ByRef ListViewName As ListView, ListViewItem As Long, lvType As Integer, ControlData As String, Optional ListViewColumn As Long)
Select Case lvType
Case 0: ListViewName.ListItems(ListViewItem) = ControlData
Case 1: ListViewName.ListItems(ListViewItem).SubItems(ListViewColumn) = ControlData
End Select
End Sub