Dear experts
Please help me compose/debug a routine to search, which line of an array, a given number appears. I though a multiple loop would be able to read through my file from array (0,0) to array (120,7) but no way will it co-operate. I've used the single loop commands below with success and tested co-ordinates manually, so believe the data is good,
Do Until Line = 120 Or Array1(Line, Column) = SearchedForNr
Column = Column + 1 'or Line = Line + 1
Loop
but the minute i put the columns and lines together in a multiple loop they only deliver either the first or last columns search co-ordinates. (or nothing at all)
I have enclosed the full code for this project, and have tried variations of do until/while = <> and or with no further success and would appreciate a full scrutiny of the code as i am a beginner and have spent a whole day on this with no success. Full points for code to simply replace mine with. am exhausted but will check in tomorrow. many thanks
**************************
**********
**********
**********
**********
**********
**********
**********
**********
****
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim SourceFile As String = "C:\test.csv"
Dim sr As New System.IO.StreamReader(Sou
rceFile)
Dim cvsFile() As String = sr.ReadToEnd().Split((Cont
rolChars.C
r))
sr.Close()
Dim TotalNumberOfLines As Integer = cvsFile.Length - 1
Dim TotalNumberOfColumns As Integer = 8
Dim Array1(TotalNumberOfLines,
TotalNumberOfColumns - 1) As String
'populate array
For i As Integer = 0 To TotalNumberOfLines
Dim fields() As String = cvsFile(i).Split(",")
For y As Integer = 0 To fields.Length - 1
Array1(i, y) = fields(y).Trim()
Next
Next
Dim SearchedForNr As Integer
SearchedForNr = TextBox4.Text
Dim Line As Integer = 0
Dim Column As Integer = 0
'*************************
**********
**********
**********
**********
**********
****
''''help needed on this routine: detemine which line of array1 , contains SearchedForNr ''''
'*************************
**********
**********
**********
**********
**********
****
Do Until Line = 120 Or Array1(Line, Column) = SearchedForNr
Do Until Column = 7 Or Array1(Line, Column) = SearchedForNr
Column = Column + 1
Loop
Line = Line + 1
Column = 0 ' reset counter for internal loop
Loop
TextBox5.Text = Line ' where SearchedForNr found
TextBox6.Text = Column 'where SearchedForNr found
End Sub
Many many thanks.
Peter
Start Free Trial