|
-
Aug 25th, 2006, 05:59 AM
#1
Thread Starter
Hyperactive Member
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:
Dim N As Integer
Do While Not rs.EOF
For N = 0 To rs.Fields.Count - 1
If rs.Fields(N).Value = "^CASH" Then
Text2.Text = rs.Fields(N).Value '<<<< store in text box "CASH"
Text3.Text = rs.Fields(N + 3).Value ' <<< store in text box "$25.00
Exit For
End If
Next N
rs.MoveNext
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.
-
Aug 25th, 2006, 06:15 AM
#2
PowerPoster
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.
-
Aug 25th, 2006, 06:59 AM
#3
Thread Starter
Hyperactive Member
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
-
Aug 25th, 2006, 03:06 PM
#4
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:
Dim s As string, strSQL as String
'assume conn is your database connection
Open "myTextFile.txt" For Input As #1
While Not EOF(1)
s = Line Input #1
'get your transaction type and amount out of s here
strSQL = "Insert Into <table name> (TransactionType, Amount) Values('" & <transaction type from text file> & "'[COLOR=Black], " & <amount from text file>[/COLOR]
conn.Execute strSQL
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|