Hi, I'm new her. I have a strange problem when compare two strings in VB 2010 express.
I use string.compare(item1, item2) It read the string from a text file to fill a combobox with existing dates.
In the beginning the compare say that item1 ="12/05" and Item2 ="12/05" not match. When get the next date it is a match. The routine check if it allready have the next date. If it is already found it get the next line from the file
If not it store the new date in a string to check against and put in the list.
I also tried different compare metod but the result is the same. It just skip the first date and then all works as planned.
Maybe i just dont see the error![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Here is the routine.
PrivateSub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim result = New List(OfString)
Using reader = New StreamReader("c:\logs\station.txt")' this is a log file with a bunch of lines registred on date and time and them the log message on each line.
Dim line As String = reader.ReadLine()
Dim take = False
Dim ldate As String = ""
Dim lastdate As String = ""
Dim n As Integer
Do While line IsNot Nothing
If Not line = ""Then
ldate = line.Substring(0, 5)
If lastdate = ""Then lastdate = ldate
End If
If Not ldate.Equals(lastdate) Then
result.Add(ldate)
lastdate = ldate
TextBox1.Text = TextBox1.Text & lastdate.ToString & vbCrLf
If lastdate.Length <= 5 Then ComboBox1.Items.Add(lastdate.ToString)
End If
line = reader.ReadLine()
Loop
End Using
ComboBox1.Items.Add(result)
End Sub
I use string.compare(item1, item2) It read the string from a text file to fill a combobox with existing dates.
In the beginning the compare say that item1 ="12/05" and Item2 ="12/05" not match. When get the next date it is a match. The routine check if it allready have the next date. If it is already found it get the next line from the file
If not it store the new date in a string to check against and put in the list.
I also tried different compare metod but the result is the same. It just skip the first date and then all works as planned.
Maybe i just dont see the error
Here is the routine.
PrivateSub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim result = New List(OfString)
Using reader = New StreamReader("c:\logs\station.txt")' this is a log file with a bunch of lines registred on date and time and them the log message on each line.
Dim line As String = reader.ReadLine()
Dim take = False
Dim ldate As String = ""
Dim lastdate As String = ""
Dim n As Integer
Do While line IsNot Nothing
If Not line = ""Then
ldate = line.Substring(0, 5)
If lastdate = ""Then lastdate = ldate
End If
If Not ldate.Equals(lastdate) Then
result.Add(ldate)
lastdate = ldate
TextBox1.Text = TextBox1.Text & lastdate.ToString & vbCrLf
If lastdate.Length <= 5 Then ComboBox1.Items.Add(lastdate.ToString)
End If
line = reader.ReadLine()
Loop
End Using
ComboBox1.Items.Add(result)
End Sub
Last edited: