Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

how to pull text from text file

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
jrisi03
Asked:
jrisi03
1 Solution
 
JacamarCommented:
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
 
rspahitzCommented:
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
 
coreytheBMXprogrammerCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now