Results 1 to 10 of 10

Thread: text file reading

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    174

    text file reading

    Hi all,

    Can anyody help me out with a code. I want to read a text file line by line and then I will get some data in the lines. I want to do some sort of opeartions may be mathematical on those data.

    Please hlp me.

    Thank you in advance

  2. #2
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: text file reading

    CODE IS
    VB Code:
    1. Dim f1
    2. dim f2
    3. set f1 =createobject("Scripting.FileSystemObject")
    4. set f2 = f1.opentextfile(filename,1) 'open file in read mode
    5. while f2.AtEndOfStream=false
    6.   lineis=f2.readline()
    7.  wend
    WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST

  3. #3
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: text file reading

    then add
    f2.close()
    WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST

  4. #4
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Re: text file reading

    Open "C:\DATA.TXT" For Input As #1
    Do While Not EOF(1)
    Input #1, vDATA

    'Process your data.......

    Loop

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    174

    Re: text file reading

    Thanks shukla. But my main problem is how to get a particular data from a line.

  6. #6
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: text file reading

    CHECK OUT THIS LINK ALSO FOR MORE DETAIL
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strLine As String, Value1 As String, Value2, Value3, Value4, Value5 As String
    3. Dim tmpDate As String
    4. Dim x As Integer
    5. Dim strData() As String
    6.  
    7. tmpDate = DTPicker1
    8.    
    9.    Open "D:\sample2.txt" For Input Lock Write As #1
    10.    Open "D:\daily.txt" For Output As #2
    11.  
    12.     Do While (Not EOF(1))
    13.     ReDim Preserve strData(x)
    14.         Line Input #1, strLine
    15.        
    16.          If InStr(1, strLine, tmpDate) Then
    17.             Parts = Split(strLine, ",")
    18.             Value1 = Parts(0)
    19.             Value2 = Parts(1)
    20.             Value3 = Parts(2)
    21.             Value4 = Parts(3)
    22.             Value5 = Parts(4)
    23.             Print #2, Value3;" ";Value1;" ";Value2
    24.         End If
    25.  
    26.  strData(x) = Value3 + " " + Value1 + " " + Value2
    27.  Print #2, strData(x)
    28.  x = x + 1
    29.     Loop
    30.    
    31. Close #1
    32. Close #2
    33. End Sub
    Last edited by shakti5385; Aug 25th, 2006 at 04:41 AM.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: text file reading

    Quote Originally Posted by jobs_arghya
    Thanks shukla. But my main problem is how to get a particular data from a line.
    That depends on the format of the line and what specific data you want to get.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: text file reading

    Quote Originally Posted by jobs_arghya
    Thanks shukla. But my main problem is how to get a particular data from a line.
    Check out the post 6

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    174

    Re: text file reading

    Thanks Shakti, At last I found a way. Hope it will work. Thanks a lot

  10. #10
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: text file reading

    Quote Originally Posted by jobs_arghya
    Thanks Shakti, At last I found a way. Hope it will work. Thanks a lot
    Your Most Welcome
    if get the solution then go to the thread tool menu and click on the resloved this thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width