Results 1 to 4 of 4

Thread: Looping Through Text File Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Looping Through Text File Question

    Hi All

    Just a question on capturing the data that i need from looping through a text file.
    I need to find a couple of records and then store them into an access db,
    so in my limited vb knowledge i have come up with this idea.
    VB Code:
    1. Dim N As Integer
    2. Do While Not rs.EOF
    3. For N = 0 To rs.Fields.Count - 1
    4.     If rs.Fields(N).Value = "^CASH" Then
    5.           Text2.Text = rs.Fields(N).Value '<<<< store in text box "CASH"
    6.           Text3.Text = rs.Fields(N + 3).Value ' <<< store in text box "$25.00
    7.           Exit For
    8.     End If
    9. Next N
    10. rs.MoveNext
    11. Loop
    to store the data, found from the loop into text boxes and then update the database from the data in the textbox.
    But i need to pick out about 40 records ie. "Credit Card", "Total Sales" etc and this would mean that i would need
    alot of invisible text boxes, so my question is, is this the best way to achieve this or is there a better way.

    Many thanks
    Last edited by Hack; Aug 25th, 2006 at 07:10 AM. Reason: Added [vbcode] [/vbcode] tags and indenting.

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Looping Through Text File Question

    Why use textboxes? Why don't you use an array? If you're using a lot of subs and the variable isn't available in them all, try using a module and dimming an array as public...so if you wanted to dim data(40) you would put "public data(40)" and it would make the variable available anywhere in the program
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Re: Looping Through Text File Question

    Hi Smux

    Thank you for your reply, it is a small app with not many subs at all, it reads a comma delimited text file, i then have to loop through it just putting the data that i need into a db. I have never tried coding what you have suggested, could you point me to a tutorial or give some guidelines please.

    Many thanks

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

    Re: Looping Through Text File Question

    Your code is looping through the database. Your words say that you have to loop through a text file. Assuming the latter is true, do something like:
    VB Code:
    1. Dim s As string, strSQL as String
    2. 'assume conn is your database connection
    3.  
    4. Open "myTextFile.txt" For Input As #1
    5. While Not EOF(1)
    6.   s = Line Input #1
    7.   'get your transaction type and amount out of s here
    8.   strSQL = "Insert Into <table name> (TransactionType, Amount) Values('" & <transaction type from text file> & "'[COLOR=Black], " &  <amount from text file>[/COLOR]
    9.   conn.Execute strSQL
    10. Wend
    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

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