none
single Max and pair Max Number

    Question

  • Hi All,

    Just trying to find Max number single or have a pair.somebody correct this code.

    Thank

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System.IO
    Imports System.Data
    Imports System.Text
    
    Public Class Form1
        Private C_ As New List(Of String)
        Private F_ As New List(Of String)
        Private S_ As New List(Of String)
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    
            F_.Add("40")
            F_.Add("40")
            F_.Add("17")
            F_.Add("4")
            F_.Add("17")
            F_.Add("95")
            F_.Add("9")
            F_.Add("49")
            F_.Add("21")
            F_.Add("69")
            F_.Add("69")
            F_.Add("96")
            F_.Add("96")
            F_.Add("69")
            F_.Add("58")
            F_.Add("58")
            F_.Add("85")
            F_.Add("68")
            F_.Add("86")
            F_.Add("86")
            F_.Add("89")
            F_.Add("89")
            F_.Add("98")
            F_.Add("15")
            F_.Add("13")
            F_.Add("3")
            F_.Add("19")
            F_.Add("35")
            F_.Add("87")
            F_.Add("42")
            F_.Add("32")
            F_.Add("24")
            F_.Add("47")
            F_.Add("78")
            F_.Add("75")
            F_.Add("43")
            F_.Add("93")
            F_.Add("73")
            F_.Add("83")
            F_.Add("27")
            F_.Add("72")
            F_.Add("27")
            F_.Add("65")
            F_.Add("62")
            F_.Add("41")
            F_.Add("14")
            F_.Add("16")
    
            C_.Add("10")
            C_.Add("10")
            C_.Add("10")
            C_.Add("10")
            C_.Add("10")
            C_.Add("10")
            C_.Add("11")
            C_.Add("11")
            C_.Add("11")
            C_.Add("12")
            C_.Add("12")
            C_.Add("12")
            C_.Add("12")
            C_.Add("12")
            C_.Add("2")
            C_.Add("2")
            C_.Add("2")
            C_.Add("3")
            C_.Add("3")
            C_.Add("3")
            C_.Add("4")
            C_.Add("4")
            C_.Add("4")
            C_.Add("4")
            C_.Add("5")
            C_.Add("5")
            C_.Add("5")
            C_.Add("5")
            C_.Add("6")
            C_.Add("6")
            C_.Add("6")
            C_.Add("6")
            C_.Add("6")
            C_.Add("6")
            C_.Add("6")
            C_.Add("7")
            C_.Add("7")
            C_.Add("7")
            C_.Add("7")
            C_.Add("8")
            C_.Add("8")
            C_.Add("8")
            C_.Add("8")
            C_.Add("9")
            C_.Add("9")
            C_.Add("9")
            C_.Add("9")
    
    
    
        End Sub
    
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
            For i As Integer = 0 To C_.Count - 1
                ListBox1.Items.Add(F_(i) & "    " & C_(i))
            Next
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Dim tempList As New List(Of Integer)
            Dim ListItems As New List(Of String)
    
            Dim ind As Integer = 0
            For Each s As String In F_
                If Integer.TryParse(s, New Integer) Then
                    If s.Length = 2 Then
                        If Not (s(0) = s(1)) Then
                            tempList.Add(CInt(s))
    
                            TextBox1.AppendText(s & "  " & C_(ind) & vbCrLf)
                            ListItems.Add(C_(ind))
    
                        End If
                    End If
                End If
    
    
                ind += 1
            Next
            For j As Integer = 0 To ListItems.Count - 1
                If ListItems(j) = ListItems.Max Then TextBox2.AppendText(ListItems.Max & " " & tempList(j) & vbCrLf)
            Next
        End Sub
    
    End Class
    

    The result should show;

    69 12
    69 12
    96 12
    96 12
    69 12


    Wednesday, March 29, 2017 12:11 PM

Answers

  • Hi

    You make it very difficult for anyone to help you by asking very vague questions.

    I think you are having difficulty by using strings in your lists instead of numeric types.

    Here is some code that is close to yours, but, with numeric lists instead. It does produce your required result. I am not sure that this is actually what you want as it shows the result reversed from your stated result wanted (this is by your doing not mine)

    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
        Private C_ As New List(Of Integer)
        Private F_ As New List(Of Integer)
        Private Sub Form1_Load(sender As System.Object, e As EventArgs) Handles MyBase.Load
            F_.AddRange({40, 40, 17, 4, 17, 95, 9, 49, 21, 69, 69, 96, 96, 69, 58, 58, 85, 68, 86, 86, 89, 89, 98, 15, 13, 3, 19, 35, 87, 42, 32, 24, 47, 78, 75, 43, 93, 73, 83, 27, 72, 27, 65, 62, 41, 14, 16})
            C_.AddRange({10, 10, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 12, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9})
        End Sub
        Private Sub Button1_Click(sender As System.Object, e As EventArgs) Handles Button1.Click
            For i As Integer = 0 To C_.Count - 1
                ListBox1.Items.Add(F_(i) & "    " & C_(i))
            Next
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As EventArgs) Handles Button2.Click
            Dim tempList As New List(Of Integer)
            Dim ListItems As New List(Of Integer)
    
            Dim ind As Integer = 0
            For Each s As String In F_
                If Integer.TryParse(s, New Integer) Then
                    If s.Length = 2 Then
                        If Not (s(0) = s(1)) Then
                            tempList.Add(CInt(s))
    
                            TextBox1.AppendText(s & "  " & C_(ind).ToString & vbCrLf)
                            ListItems.Add(C_(ind))
    
                        End If
                    End If
                End If
                ind += 1
            Next
            For j As Integer = 0 To ListItems.Count - 1
                If ListItems(j) = ListItems.Max Then TextBox2.AppendText(ListItems.Max & " " & tempList(j) & vbCrLf)
            Next
        End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by mipakteh Wednesday, March 29, 2017 2:27 PM
    Wednesday, March 29, 2017 1:27 PM

All replies

  • Hi

    You make it very difficult for anyone to help you by asking very vague questions.

    I think you are having difficulty by using strings in your lists instead of numeric types.

    Here is some code that is close to yours, but, with numeric lists instead. It does produce your required result. I am not sure that this is actually what you want as it shows the result reversed from your stated result wanted (this is by your doing not mine)

    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
        Private C_ As New List(Of Integer)
        Private F_ As New List(Of Integer)
        Private Sub Form1_Load(sender As System.Object, e As EventArgs) Handles MyBase.Load
            F_.AddRange({40, 40, 17, 4, 17, 95, 9, 49, 21, 69, 69, 96, 96, 69, 58, 58, 85, 68, 86, 86, 89, 89, 98, 15, 13, 3, 19, 35, 87, 42, 32, 24, 47, 78, 75, 43, 93, 73, 83, 27, 72, 27, 65, 62, 41, 14, 16})
            C_.AddRange({10, 10, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 12, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9})
        End Sub
        Private Sub Button1_Click(sender As System.Object, e As EventArgs) Handles Button1.Click
            For i As Integer = 0 To C_.Count - 1
                ListBox1.Items.Add(F_(i) & "    " & C_(i))
            Next
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As EventArgs) Handles Button2.Click
            Dim tempList As New List(Of Integer)
            Dim ListItems As New List(Of Integer)
    
            Dim ind As Integer = 0
            For Each s As String In F_
                If Integer.TryParse(s, New Integer) Then
                    If s.Length = 2 Then
                        If Not (s(0) = s(1)) Then
                            tempList.Add(CInt(s))
    
                            TextBox1.AppendText(s & "  " & C_(ind).ToString & vbCrLf)
                            ListItems.Add(C_(ind))
    
                        End If
                    End If
                End If
                ind += 1
            Next
            For j As Integer = 0 To ListItems.Count - 1
                If ListItems(j) = ListItems.Max Then TextBox2.AppendText(ListItems.Max & " " & tempList(j) & vbCrLf)
            Next
        End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by mipakteh Wednesday, March 29, 2017 2:27 PM
    Wednesday, March 29, 2017 1:27 PM
  • thank

     Dim ListItems As New List(Of Integer)

    ListItems.Add(CInt(C_(ind)))

    Wednesday, March 29, 2017 2:28 PM