Solved

VB 2005 code problem

Posted on 2007-11-14
2
171 Views
Last Modified: 2013-11-26
Hi

I am having a problem with the following function that I brought over from VBA into VB 2005
The error is at the line marked 'XXXX and it reads .Selected is not a member of a ListView

    Function sListSelection() As String
        'returns a string separatted by commas of indices selected in a list box
        Dim lngIndex As Long
        Dim S As String
        Dim Count As Long
        Count = 0
        With frmR.lsbActionR
            For lngIndex = 1 To .Items.Count
                If .Selected(lngIndex - 1) Then 'XXXX
                    If Count = 0 Then
                        S = CStr(lngIndex - 1)
                    Else
                        S = S & "," & CStr(lngIndex - 1)
                    End If
                    Count = Count + 1
                End If
            Next lngIndex
        End With
        sListSelection = S
    End Function
0
Comment
Question by:murbro
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 20281202
The best way to do this is to use the .SelectedIndices property of the listview which returns a collection containing the selected indices.

Now you could transform that to a string in a similar way:

    Function sListSelection() As String
        'returns a string separatted by commas of indices selected in a list box
        Dim S As String
        With frmR.lsbActionR
            For Each SelectedIndex As Integer In .SelectedIndices
                        S = S & "," & CStr(SelectedIndex)
            Next
        End With
        Return S.Substring(1)
    End Function

Or work directly with the collection.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20281212
try with:
If .Items(IngIndex).Selected Then

but will be better:
Dim Index as Integer
For lngIndex = 1 To .SelectedIndices.Count
                   Index = SelectedIndices(IngIndex)
                    If Count = 0 Then
                        S = CStr(Index - 1)
                    Else
                        S = S & "," & CStr(Index - 1)
                    End If
                    Count = Count + 1
Next lngIndex
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now