7 Replies - 436 Views - Last Post: 27 June 2013 - 05:51 AM Rate Topic: -----

#1 fanglign  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 48
  • Joined: 24-June 13

remove duplicates

Posted 26 June 2013 - 08:25 AM

Dim curModuleCode, modulecode(1000) As String

        Dim objModuleCode As Object
        Dim i, j As Integer
        DataGridView2.ColumnCount = 5
        DataGridView2.Columns(0).Name = "School"
        DataGridView2.Columns(1).Name = "Campus"
        DataGridView2.Columns(2).Name = "AdminNo"
        DataGridView2.Columns(3).Name = "ModuleCode"
        DataGridView2.Columns(4).Name = "ModuleGrp"

        j = 0
        For Each line As String In System.IO.File.ReadAllLines("H:\FYP\sampledata.txt")
            objModuleCode = line.Split(";")
            curModuleCode = objModuleCode(3)

            'DataGridView2.Rows.Add(line.Split(";"))
            'Dim i = DataGridView2.Rows.Count

            'Check whether there is duplicates
            For i = 0 To j
                If modulecode(i) = curModuleCode Then

                    Exit For
                End If
            Next


            'The current module code is not duplicate
            If i = j + 1 Then

                DataGridView2.Rows.Add(line.Split(";"))
                modulecode(i) = curModuleCode

            End If
        Next



above is my cod, purpose is to removed duplicates from the text file i read from contains the following:

Sch;campus;adminNo;modulecode;modulegrp

SEG;AMK;111124Q;EG3932;EG3932-G1
SEG;AMK;111124Q;EG3933;EG3933-G1
SEG;AMK;114509N;EG3901;EG3901-G1
SEG;AMK;114509N;EG3902;EG3902-G1
SEG;AMK;114509N;EG3904;EG3904-G1
SEG;AMK;114509N;EG3905;EG3905-G1
SEG;AMK;114509N;EG3908;EG3908-G1
SEG;AMK;114509N;EG3909;EG3909-G1
SEG;AMK;114509N;EG3921;EG3921-G1
SEG;AMK;114509N;EGS650;EGS650-G1
SEG;AMK;114507D;EG3901;EG3901-G1
SEG;AMK;114507D;EG3902;EG3902-G1
SEG;AMK;114507D;EG3904;EG3904-G1
SEG;AMK;114507D;EG3905;EG3905-G1
SEG;AMK;114507D;EG3908;EG3908-G1
SEG;AMK;114507D;EG3909;EG3909-G1
SEG;AMK;114507D;EG3921;EG3921-G1
SEG;AMK;114507D;EGS302;EGS302-G1

i displayed the data into DGV. now i have another form only want to show the modulecode column with distinct data.
please advice. thanks

This post has been edited by macosxnerd101: 26 June 2013 - 08:28 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: remove duplicates

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9363
  • View blog
  • Posts: 35,172
  • Joined: 12-June 08

Re: remove duplicates

Posted 26 June 2013 - 08:34 AM

Quote

i displayed the data into DGV. now i have another form only want to show the modulecode column with distinct data.
please advice.

Will you be more specific? Advise on what? Are you getting an error? If so what is the error text? Is the code not functioning as expected? If so what is it doing, and what *should* it be doing? Remember we are not there looking over your shoulder, and that means you need to be super clear with us on what you are looking to do, are doing, and require.
Was This Post Helpful? 0
  • +
  • -

#3 fanglign  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 48
  • Joined: 24-June 13

Re: remove duplicates

Posted 26 June 2013 - 08:31 PM

View Postmodi123_1, on 26 June 2013 - 08:34 AM, said:

Quote

i displayed the data into DGV. now i have another form only want to show the modulecode column with distinct data.
please advice.

Will you be more specific? Advise on what? Are you getting an error? If so what is the error text? Is the code not functioning as expected? If so what is it doing, and what *should* it be doing? Remember we are not there looking over your shoulder, and that means you need to be super clear with us on what you are looking to do, are doing, and require.


i want the "ModuleCode" column displayed in datagridview with distinct data.
i dont know why the for loop i did is not working in getting rid of the duplicates.
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: remove duplicates

Posted 26 June 2013 - 09:16 PM

View Postfanglign, on 26 June 2013 - 09:31 PM, said:

i dont know why the for loop i did is not working in getting rid of the duplicates.

Place a breakpoint on line 21. When it stops, check the value in j. Ask yourself how many times the loop will execute.

If you don't know how to set a breakpoint, check out the debugging tutorials here or here.
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,097
  • Joined: 02-July 08

Re: remove duplicates

Posted 26 June 2013 - 10:43 PM

Use a List(Of String) and with each iteration of the loop you add the 'ModuleCode' if it does not exist and parse the line, if the List does contain the next 'ModuleCode' then Continue For.
Was This Post Helpful? 0
  • +
  • -

#6 fanglign  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 48
  • Joined: 24-June 13

Re: remove duplicates

Posted 26 June 2013 - 11:24 PM

View Post_HAWK_, on 26 June 2013 - 10:43 PM, said:

Use a List(Of String) and with each iteration of the loop you add the 'ModuleCode' if it does not exist and parse the line, if the List does contain the next 'ModuleCode' then Continue For.


thanks for the reply, can help me with the coding? cause i dont really have the basic in programming but i need this for my project. thanks!
Was This Post Helpful? -1
  • +
  • -

#7 fanglign  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 48
  • Joined: 24-June 13

Re: remove duplicates

Posted 27 June 2013 - 12:04 AM

View Post_HAWK_, on 26 June 2013 - 10:43 PM, said:

Use a List(Of String) and with each iteration of the loop you add the 'ModuleCode' if it does not exist and parse the line, if the List does contain the next 'ModuleCode' then Continue For.


can help me with the coding, i really dont know how i should go about doing it
thanks!
Was This Post Helpful? 0
  • +
  • -

#8 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 975
  • Joined: 09-May 09

Re: remove duplicates

Posted 27 June 2013 - 05:51 AM

Im sure by now you know that here at Dream in Code we provide help and we do not do homework.

attempt to resolve the issue and post you code, we will be glad to nudge you in the right direction


think about it this way, read each line of text into an array
get the value of position 0 and store in variable1
get the value of position 0 and store in variable2
loop variable2 through the array check it the value = variable1
if so delete, if not move on
when the you reach the end of the array, set variable2 iterator back to 0
increment the iterator for variable1 by 1
perform the looping again

Remember to check if the iterator values are the same and ignore the values or each loop there will appear to be at least 1 duplicate

This post has been edited by deery5000: 27 June 2013 - 06:02 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1