5 Replies - 520 Views - Last Post: 26 January 2014 - 02:04 AM Rate Topic: -----

#1 goodhamody  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-January 14

Comparison of rows in VB

Posted 23 January 2014 - 12:16 AM

Hello guys,

I have a column that contains the following values:

BCDEABCDE          
                    
BCDEABCDEA          
ABCDEABCDE          
A*CBAAECCE          
ABC EA*CDE          



how do I take the first Row value "BCDEABCDE " and compare it with each remaining row to get some values such as(the total matched number, the total unmatched number?

For example, if i compare the first row"BCDEABCDE " with the second row,which is empty,
the total matched number = 0
the total unmatched number = 10

Is This A Good Question/Topic? 0
  • +

Replies To: Comparison of rows in VB

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9389
  • View blog
  • Posts: 35,262
  • Joined: 12-June 08

Re: Comparison of rows in VB

Posted 23 January 2014 - 07:59 AM

They key is to know about collections. Can you navigate a collection? Iterate through it with a loop of any sorts?

Here's an example of what I mean:

        Dim foo As New DataSet  '-- main item.
        foo.Tables.Add("bar") '-- a dataset holds a collection of tables
        foo.Tables(0).Columns.Add("col1") '-- any given table object holds a collection of columns

        foo.Tables(0).Rows.Add("abc") '-- any given table object holds a collection of rows with cells/items per the number of columns.
        foo.Tables(0).Rows.Add("123")
        foo.Tables(0).Rows.Add("def")
        foo.Tables(0).Rows.Add("abc")

        Console.WriteLine(foo.Tables(0).Rows(0).Item(0)) '-- example of getting an individual cell.

        If CStr(foo.Tables(0).Rows(0).Item(0)) = CStr(foo.Tables(0).Rows(0).Item(0)) Then '-- cells are generic 'object' types, so it does help to get them to their right data types.
            Console.WriteLine("match")
        Else
            Console.WriteLine("no match")
        End If

        '-- with all collections you can tell how many objects are in it.. so you can use a for loop to navigate through them all!
        For i As Int32 = 0 To foo.Tables(0).Rows.Count - 1 
            Console.WriteLine(foo.Tables(0).Rows(i).Item(0))
        Next

Was This Post Helpful? 0
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 485
  • View blog
  • Posts: 3,248
  • Joined: 12-January 10

Re: Comparison of rows in VB

Posted 23 January 2014 - 10:51 AM

I hate foo lol

dont forget the (0) -- this tells you the position of the item in question
Was This Post Helpful? 0
  • +
  • -

#4 goodhamody  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-January 14

Re: Comparison of rows in VB

Posted 25 January 2014 - 11:20 PM

thank you for your reply but this still doesn't show the comparison that I need.
Was This Post Helpful? 0
  • +
  • -

#5 Minimalist  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 115
  • Joined: 13-November 13

Re: Comparison of rows in VB

Posted 26 January 2014 - 01:57 AM

O.K I have done a few lines of code to show you one way of comparing the characters of 2 strings. So I assume you know how to return your items from the columns I just use 2 of your strings by using 2 textboxes, 2 labels and one button where the code goes in.
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Text = "BCDEABCDE"
        TextBox2.Text = "ABCDEABCDE"
    End Sub

    Private Sub cmdCompare_Click(sender As Object, e As EventArgs) Handles cmdCompare.Click
        Dim str1, str2 As String
        Dim strLen As Integer = 0
        Dim charMatch, i, j As Integer : charMatch = 0 : i = 0 : j = 0
        str1 = Trim(TextBox1.Text)
        str2 = Trim(TextBox2.Text)
        strLen = Len(str1)

        For i = 0 To str1.Length - 1
            While j < str2.Length AndAlso str2.Chars(j) <> " "c
                If str1.Chars(i) = str2.Chars(j) Then
                    charMatch += 1
                    j += 1
                    Exit While
                Else
                    j += 1
                End If
            End While
        Next
        Label1.Text = "Matches" & "  " & CStr(charMatch)
        Label2.Text = "Non Matches" & "  " & CStr(str1.Length - charMatch)
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#6 Minimalist  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 115
  • Joined: 13-November 13

Re: Comparison of rows in VB

Posted 26 January 2014 - 02:04 AM

Here is picture:

Attached File(s)

  • Attached File  1.bmp (323.29K)
    Number of downloads: 18

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1