Quote Originally Posted by dbasnett View Post
When looking at multiple variables being equal to 'some value' (0 in this example) I like to use this form

Code:
        If g1 = 0 AndAlso g2 = g1 AndAlso g3 = g1 AndAlso g4 = g1 Then

        End If
That way if 'some value' changes I only have to change a little bit of code. The other option is to use another variable or constant for 'some value'.

thank you for your reply


and this the code i use

Code:
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Windows.Forms.Button
Imports Microsoft.VisualBasic.FileIO
Imports System.IO
Public Class AAABB
    Friend Class DataItemList
        Property DataItems As List(Of DataItem)
       

        Friend Class DataItem
            Public ti As String
            Public theDate As DateTime
            Public o As Double
            Public h As Double
            Public l As Double
            Public cl As Double
            Public vo As Integer

            Overrides Function ToString() As String
                Return String.Format("{0},{1},{2},{3},{4},{5},{6}", ti, theDate.ToString("yyyyMMdd"), o, h, l, cl, vo)
            End Function

        End Class

        Sub AddOrUpdate(d As DataItem)
            If DataItems.Exists(Function(x) x.ti = d.ti AndAlso x.theDate = d.theDate) Then
                Dim idx = DataItems.FindIndex(Function(x) x.ti = d.ti AndAlso x.theDate = d.theDate)
                DataItems(idx) = d
            Else
                DataItems.Add(d)
            End If
           
        End Sub
        

        Sub LoadData(src As String)
            Using tfp = New TextFieldParser(src)
                tfp.TextFieldType = FieldType.Delimited
                tfp.Delimiters = {","}
                tfp.ReadLine() ' skip headers.
                Dim s As String()
                Dim lineNo As Integer = 1 ' we've skipped the first line

                While Not tfp.EndOfData
                    s = tfp.ReadFields
                    If s.Count = 7 Then
                        ' you /should/ parse the data more thoroughly than this, e.g. with TryParse.
                        Me.AddOrUpdate(New DataItemList.DataItem With
                            {.ti = s(0),
                             .theDate = DateTime.ParseExact(s(1), "yyyyMMdd", Nothing),
                             .o = Double.Parse(s(2)),
                             .h = Double.Parse(s(3)),
                             .l = Double.Parse(s(4)),
                             .cl = Double.Parse(s(5)),
                             .vo = Int32.Parse(s(6))})

                    Else
                        MsgBox(String.Format("Error in file {0} at line {1}.", src, lineNo))
                    End If

                    lineNo += 1

                End While
            End Using
        End Sub

        Sub New()
            DataItems = New List(Of DataItem)
        End Sub

    End Class


    Public Sub TEXTAAA()
        Dim myData = New DataItemList

        myData.LoadData("C:\AAAA.txt")
        myData.LoadData("C:\BBBB.txt")
        Dim sortedData = myData.DataItems.OrderBy(Function(d) d.ti).ThenByDescending(Function(d) d.theDate)

        ' show the result
        Dim objWriter As New System.IO.StreamWriter("C:\test.txt")
        objWriter.Write(String.Join(vbCrLf, sortedData))
        objWriter.Close()

        System.Diagnostics.
       Process.Start("notepad", "C:\test.txt")

        ' unselect the text for readability
        'TextBox1.SelectionLength = 0
        'TextBox1.SelectionStart = 0

    End Sub
End Class

this code will remove duplicate line and will sort them


what you provied is good but what i need to get to is
1- if g1,g2,g3,g4 =0 then line will be removed like

DDS,20110523,0,0,0,0,24


2-if g1,g2,g3,g4 =g4 of the line before then line will be removed like

the line as
DDS,20110526,1.1,1.1,1.1,1.1,29 in this line you will see 1.1 in array 2 and also in array 3,array 4,array 5 (array 1=g1,array 2=g2 ........)

but in the line below that will be after the line above

DDS,20110525,2.4,2.7,2.3,1.1,22 in this line 1.1 is in (array 5 )

if any line that array 2 =array 3= array 4 = array 5 and the line after contain the same value in array 5 the line will be removed

but if any line that array 2 =array 3= array 4 = array 5 and the after contain different value in array 5 the line will not be removed like


DDS,20110526,33,33,33,33,29
DDS,20110525,2.4,2.7,2.3,40,22

in the frist line array 2 to array 5 is the same value

but array 5 in the second line is different


i hope my explanation is clear

and thank you again for your time and your understanding