Solved

VB 2005 code problem

Posted on 2007-11-14
2
179 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
[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 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 our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with consolidating excel files using VB.net 2 35
Object Oriented Programming, C#, referencing, scoping. 13 85
Powershell File Sort 8 45
Reactjs with .NET 3 74
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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