0

I need help in VB.NET on how to read the entile file line by line which has about 500 lines, and then search line by line if search match found and then display it
I have arrange them into an array but because the search need 2 matches on in each line then display it when each line meet those 2 matches
this code only display the first one found only and also not diplayin the entire lines

anyone can help me I appreacite it so much

thank you

this is my code so far

Dim fileContents() As String
        fileContents = My.Computer.FileSystem.ReadAllText("C:\Documents and Settings\user0044\My Documents\WindowsApplication2\WindowsApplication2\bin\Debug\MyFile.txt").Split(vbCrLf)
        For x As Integer = 0 To fileContents.Length - 1
            If fileContents(x).Contains(ComboBox1.Text) Then
                     TextBox1.Text = fileContents(x).Substring(1, fileContents(x).IndexOf(" "))
             End If

        Next x

    End Sub
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by debasisdas
0

the following code is in VB 6.0 conert to .net as desired.

Private Sub Cmdcount_Click()
List2.Clear
T2 = Trim(Text2.Text)
Open Trim(Text1.Text) For Input As #1
Do Until EOF(1)
Line Input #1, n
LNWORDCOUNT = 0
LNCOUNT = LNCOUNT + 1
T1 = n
CT = 1
Do While CT <= Len(T1)
ctr = InStr(CT, T1, T2)
If ctr <> 0 Then
CT = ctr + 1
CTR1 = CTR1 + 1
LNWORDCOUNT = LNWORDCOUNT + 1
Else
Exit Do
End If
Loop
'Print LNCOUNT & "    " & LNWORDCOUNT
If LNWORDCOUNT <> 0 Then
List2.AddItem "Line No :" & LNCOUNT & "    " & "Occurance :" & LNWORDCOUNT
End If
Loop
Label1.Caption = "Total Occurance In File : " & CTR1
Close #1

End Sub

Private Sub CmdExit_Click()
End
End Sub

Private Sub CmdOpen_Click()
Dim n As String
Dim ctr As Integer
Dim CTR1 As Integer
Dim STR As String
Dim i As Integer
Dim LNCOUNT As Integer
Dim LNWORDCOUNT As Integer
List2.Clear
Label1.Caption = ""
On Error GoTo err1
cd.DialogTitle = "Open File"
cd.InitDir = "C:\"
cd.CancelError = True
cd.ShowOpen
Text1.Text = cd.FileName
List1.Enabled = True
Exit Sub
err1:
MsgBox Err.Description

End Sub

Private Sub List1_DblClick()
Text2.Text = Trim(List1.List(List1.ListIndex))
End Sub

Private Sub Text2_Change()
Cmdcount.Enabled = Len(Text2.Text) > 0
End Sub

please ignore the unnecessary part of the code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.