Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB 2005 code problem

Posted on 2007-11-14
2
Medium Priority
?
184 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 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