Results 1 to 13 of 13

Thread: [RESOLVED] Can't seem to use my Public Sub.

  1. #1

    Thread Starter
    Lively Member RickyOswaldIOW's Avatar
    Join Date
    Sep 2007
    Location
    Ryde, Isle of Wight
    Posts
    120

    Resolved [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?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Can't seem to use my Public Sub.

    just remove the brackets after updateListview
    vb Code:
    1. 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.Index0frmcompanydetails.txtAccountName.Text
    Last edited by VBFnewcomer; Sep 21st, 2007 at 06:43 AM. Reason: added one more option

  4. #4
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    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.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  5. #5

    Thread Starter
    Lively Member RickyOswaldIOW's Avatar
    Join Date
    Sep 2007
    Location
    Ryde, Isle of Wight
    Posts
    120

    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

  6. #6
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Can't seem to use my Public Sub.

    was post #3 of no help? :sob:

  7. #7
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    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

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  8. #8

    Thread Starter
    Lively Member RickyOswaldIOW's Avatar
    Join Date
    Sep 2007
    Location
    Ryde, Isle of Wight
    Posts
    120

    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!

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  10. #10

    Thread Starter
    Lively Member RickyOswaldIOW's Avatar
    Join Date
    Sep 2007
    Location
    Ryde, Isle of Wight
    Posts
    120

    Re: Can't seem to use my Public Sub.

    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

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  12. #12

    Thread Starter
    Lively Member RickyOswaldIOW's Avatar
    Join Date
    Sep 2007
    Location
    Ryde, Isle of Wight
    Posts
    120

    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 :|

  13. #13
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    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
    Last edited by Mxjerrett; Sep 21st, 2007 at 07:07 AM.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

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