Click here to Skip to main content
15,915,600 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Compute Sum on a column based on criteria Pin
Member 1412885424-Jan-19 21:07
Member 1412885424-Jan-19 21:07 
AnswerRe: Compute Sum on a column based on criteria Pin
Ralf Meier24-Jan-19 21:22
mveRalf Meier24-Jan-19 21:22 
QuestionUnable to load xlsm file with Office 2016 Pin
manju 323-Jan-19 20:18
manju 323-Jan-19 20:18 
QuestionRe: Unable to load xlsm file with Office 2016 Pin
Richard MacCutchan23-Jan-19 22:40
mveRichard MacCutchan23-Jan-19 22:40 
AnswerRe: Unable to load xlsm file with Office 2016 Pin
Mycroft Holmes24-Jan-19 11:20
professionalMycroft Holmes24-Jan-19 11:20 
GeneralRe: Unable to load xlsm file with Office 2016 Pin
Richard MacCutchan24-Jan-19 22:08
mveRichard MacCutchan24-Jan-19 22:08 
QuestionRe: Unable to load xlsm file with Office 2016 Pin
Maciej Los24-Jan-19 2:49
mveMaciej Los24-Jan-19 2:49 
QuestionA Class Model with sort capabilities, Linq Sort, Array Sort instead of OrderBy Pin
jkirkerx17-Jan-19 8:45
professionaljkirkerx17-Jan-19 8:45 
I was asked to sort a list of contacts and said Ok thinking it would be pretty easy using OrderBy in Linq. Then I ran the program and looked at the data and found it more difficult.

The customer decided to make the contact names like this, and I wasn't able to sort the 2nd part
Acme Company - John Doe
Acme Company - Abe Frank

I kept getting the same result of an unordered list using OrderBy(Function(x) x.FCONTACT)
Then Somehow I got side tracked into using Array.Sort, contacts.Sort() and ended up creating this new class with sort helpers that I can't get working.

I think I'm on the right track here, so went down this road to get a better understanding.
I get an intellisense error on Sort, and when I run it I get a Unhandled exception of can't cast to ContactsList in the sortContactAscendingHelper when it reads the single line of code.
contacts.Sort(ContactsList.SortContactAscending())
What have I tried, well this basically. I'm driving down a dark unfamiliar street in the rain on this and can't find much help on the subject.
Public Class ContactsList
        Implements IComparable

        Public Property FID As String
        Public Property FCHECK As Boolean
        Public Property FCUSTNO As String
        Public Property FCOMPANY As String
        Public Property FCONTACT As String
        Public Property FEMAIL As String

        // This satisfies IComparable
        Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo
            Return FCONTACT.CompareTo(obj)
        End Function

        Public Shared Function SortContactAscending() As IComparer

            Return CType(New SortContactAscendingHelper(), IComparer)

        End Function

        Public Shared Function SortContactDescending() As IComparer

            Return CType(New SortContactDescendingHelper(), IComparer)

        End Function        

        Private Class SortContactAscendingHelper : Implements IComparer

            Function Compare(ByVal a As Object, ByVal b As Object) As Integer Implements IComparer.Compare

                Dim c1 As ContactsList = CType(a, ContactsList)
                Dim c2 As ContactsList = CType(b, ContactsList)

                Return String.Compare(c1.FCONTACT, c2.FEMAIL)

            End Function

        End Class

        Private Class SortContactDescendingHelper : Implements IComparer

            Function Compare(ByVal a As Object, ByVal b As Object) As Integer Implements IComparer.Compare

                Dim c1 As ContactsList = CType(a, ContactsList)
                Dim c2 As ContactsList = CType(b, ContactsList)

                Return String.Compare(c2.FEMAIL, c1.FCONTACT)

            End Function

        End Class

    End Class
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: A Class Model with sort capabilities, Linq Sort, Array Sort instead of OrderBy Pin
Mycroft Holmes17-Jan-19 12:39
professionalMycroft Holmes17-Jan-19 12:39 
GeneralRe: A Class Model with sort capabilities, Linq Sort, Array Sort instead of OrderBy Pin
jkirkerx17-Jan-19 13:19
professionaljkirkerx17-Jan-19 13:19 
QuestionCode not taking pictures from webcam when form in system tray Pin
Frankie_M15-Jan-19 23:46
Frankie_M15-Jan-19 23:46 
AnswerRe: Code not taking pictures from webcam when form in system tray Pin
Eddy Vluggen20-Jan-19 1:57
professionalEddy Vluggen20-Jan-19 1:57 
GeneralRe: Code not taking pictures from webcam when form in system tray Pin
Frankie_M21-Jan-19 22:14
Frankie_M21-Jan-19 22:14 
QuestionLosing Link state with CHARFORMAT2 definition ;Closed Pin
mo149215-Jan-19 12:56
mo149215-Jan-19 12:56 
Questiontest compile mode versus production compile mode Pin
dcof7-Jan-19 5:10
dcof7-Jan-19 5:10 
AnswerRe: test compile mode versus production compile mode Pin
Richard MacCutchan7-Jan-19 5:33
mveRichard MacCutchan7-Jan-19 5:33 
GeneralRe: test compile mode versus production compile mode Pin
dcof7-Jan-19 9:42
dcof7-Jan-19 9:42 
GeneralRe: test compile mode versus production compile mode Pin
Richard MacCutchan7-Jan-19 9:50
mveRichard MacCutchan7-Jan-19 9:50 
GeneralRe: test compile mode versus production compile mode Pin
dcof8-Jan-19 6:17
dcof8-Jan-19 6:17 
Questioncall a Sub with a dynamic type parameter. Pin
desanti2-Jan-19 11:03
desanti2-Jan-19 11:03 
AnswerRe: call a Sub with a dynamic type parameter. Pin
Richard MacCutchan2-Jan-19 22:10
mveRichard MacCutchan2-Jan-19 22:10 
GeneralRe: call a Sub with a dynamic type parameter. Pin
desanti3-Jan-19 4:35
desanti3-Jan-19 4:35 
GeneralRe: call a Sub with a dynamic type parameter. Pin
Richard MacCutchan3-Jan-19 6:33
mveRichard MacCutchan3-Jan-19 6:33 
GeneralRe: call a Sub with a dynamic type parameter. Pin
Dave Kreskowiak3-Jan-19 6:36
mveDave Kreskowiak3-Jan-19 6:36 
AnswerRe: call a Sub with a dynamic type parameter. Pin
Eddy Vluggen2-Jan-19 22:14
professionalEddy Vluggen2-Jan-19 22:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.