?
Solved

how to pull text from text file

Posted on 2003-03-20
3
Medium Priority
?
178 Views
Last Modified: 2008-03-10
im making this program which converts txt file in tiff files.
the txt file contains my corporations employee records
so i have the program break it up and make it different tiff files
i need to pull all of the ssn's from the text file

how do i pull that from the text file and put it in another text file

remember this is for VB
0
Comment
Question by:jrisi03
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
Jacamar earned 60 total points
ID: 8174697
Ok, assuming that your textfile is comma delimitted. (format as follows)


First, Last, age
Bob, McDonald, 32
Joe, Sampson, 30
ect....

to input the text and create 3 files (one for first, one for last, and one for age) paste the following code.

dim stFilename as string
dim array1() as string

stFilename = app.path & "\Employee.txt"

Open stFilename for input as #1
Redim array1(1 to 3, 1 to 1)
Input #1,array1(1,1)
Input #1, array1(2,1)
Input #1, array1(3,1)
inI = 1
Do while not EOF(1)
inI = inI + 1
Redim array1(1 to 3, 1 to inI)
Input #1, array1(1,inI)
INput #1, array1(2,inI)
INput #1, array1(3,inI)
Loop

Close #1

stFilename = app.path & "\Firstname.txt"
Open stFilename for output as #2

For inJ = 1 to inI
Print #1, array1(1,inI)
Next inJ
Close #2

stFilename = app.path & "\Lastname.txt"
Open stFilename for output as #3

For inJ = 1 to inI
Print #1, array1(2,inI)
Next inJ
Close #3

stFilename = app.path & "\Age.txt"
Open stFilename for output as #4

For inJ = 1 to inI
Print #1, array1(3,inI)
Next inJ
Close #4

End sub
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8175517
The other method would be to extract the SS# from a fixed position, which is done using the substring functions: left$, mid$, right$.

Most likely, your code would look like this for fixed-position values:

open "SomeFile.txt" for binary as #1
strTextFileData = input$(lof(1), #1)
close #1

strSSN = mid$(strTextFileData, intStartPosition, 11) ' 11-character SS# including dashes
0
 

Expert Comment

by:coreytheBMXprogrammer
ID: 8178941
You could use jacamar's code but change some code to allow an undefined number of conversions. Just use a few more variables to do it and put in in a loop.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question