4 Replies - 5361 Views - Last Post: 03 March 2009 - 12:37 AM Rate Topic: -----

#1 maha1608  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 17-July 08

Prevoius Line of Text file in VB.net

Posted 06 August 2008 - 03:00 AM

Hi ,
I am practising in VB.NET. I am Reading a Text File using Stream Reader. I am Reading line by line . At one point of time , If I want to go back and Read the Previous line,, Is there any method to implement that.. I have tried calling to function ( whose argument is Line number) which opens the same text File , and read upto theline number , but it does n't work as expected ,, Can anyone give me an idea to overcome it .

Thanks in Advance .

Is This A Good Question/Topic? 0
  • +

Replies To: Prevoius Line of Text file in VB.net

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Prevoius Line of Text file in VB.net

Posted 06 August 2008 - 08:55 AM

The StreamReader object is a forward reading only, so you cannot go back. You will need to start at the beginning again.

Use a FileStream using the Seek method. Seek allows you to move to any position in the file.
Was This Post Helpful? 0
  • +
  • -

#3 maha1608  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 17-July 08

Re: Prevoius Line of Text file in VB.net

Posted 06 August 2008 - 08:55 PM

View Postjayman9, on 6 Aug, 2008 - 08:55 AM, said:

The StreamReader object is a forward reading only, so you cannot go back. You will need to start at the beginning again.

Use a FileStream using the Seek method. Seek allows you to move to any position in the file.




Thnks for your information . What are Parameters that are to given for the seek method, i am asking like line number ,,,
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Prevoius Line of Text file in VB.net

Posted 06 August 2008 - 09:06 PM

Here is some information on the Seek Method of the FileStream Class
Was This Post Helpful? 0
  • +
  • -

#5 socca31mentel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-December 08

Re: Prevoius Line of Text file in VB.net

Posted 03 March 2009 - 12:37 AM

View PostPsychoCoder, on 6 Aug, 2008 - 08:06 PM, said:

Here is some information on the Seek Method of the FileStream Class


Hi, i am sonnya. i need your help.

currently i am facing issue to search previous line data from text file.
example :
Line 1 : OKC1,3ch,1295,11333,1065,0,1998,-1999,2996,11344,
Line 2 : 3784,3776,3776,14922,1939,MY0J825J4784792AJ1HV,
so the key is MY0J825J4784792AJ1HV. based on the key, i want to read status in the line 1 ( status OKC1 ). but i got problem.

what is coding in VB to read previous line after i read the line 2 to find the key ?

below is part of my coding
Do While Not EOF(1)
			
			Line Input #1, StrLineInput
			
			StrSrhResult = InStr(StrLineInput, StrScanSN)
			StrTestPass = InStr(StrLineInput, "OK")
			StrTestFail = InStr(StrLineInput, "NG")
	
			If (InStr(StrLineInput, StrScanSN) <> 0 Or Null) Then
				
'				If (InStr(StrLineInput, txtDellPart.Text) <> 0 Or Null) Then
'
'				End If
'				Dim strArray() As String
'				Dim strLen As Integer
'				Dim getPos As Integer
'				Dim getDate As Date
'				Dim getTime As Date
				strLen = Len(StrLineInput)
				ReDim strArray(strLen)
			
				strArray(strLen) = Trim(StrLineInput)
				getPos = InStr(strArray(strLen), " ")
				getPos = getPos + 1
				getDate = Format(getDate, "mm/dd/yy hh:mm")
	
'				Dim getDiff As Long
				getDiff = DateDiff("S", tempDate, getDate)
		
				If getDiff > 0 Then
					tempDate = getDate
		
		
					If (InStr(StrLineInput, "OK") <> 0 Or Null) Then
						IntResult = 1
						result = "PASS"
						getLineInput = StrLineInput
					End If
					If (InStr(StrLineInput, "NG") <> 0 Or Null) Then
						

						 Do While Not EOF(1)
						 Line Input #1, StrLineInput

							 If (InStr(StrLineInput, StrScanSN) <> 0 Or Null) Then
								If (InStr(StrLineInput, "OK") Or Null) Then
									IntResult = 1
									result = "PASS"
									getLineInput = StrLineInput
								End If
								
								If (InStr(StrLineInput, "NG") <> 0 Or Null) Then
									IntResult = 2
								End If
							End If
						 Loop
									  
					End If
				   
				End If
			End If
		Loop



Thanks before...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1