Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ascii Text to Access Database

Status
Not open for further replies.

zqtqzq

Programmer
Jul 23, 2003
61
0
0
A2
i need a code snippet to read an ASCII text file delineated by | (pipe sign) and transfer the data to an Access Database

The data i have, some are delineated by space, some by pipe sign i.e |
 
You might find the Split() function useful for breaking a text string into an array.
 
kindly expantiate on this function.
i have the datarow delineated by | and space,
i ll appreciate
 
Suppose you have this string:
sLine = "blah| blah blah| | foo| bar"

Now you break the string with Split() it on "| ":
MyFields() = Split(sLine, "| ")

Now your have this array:
MyFields(0) = "blah"
MyFields(1) = "blah blah"
MyFields(2) = ""
MyFields(3) = "foo"
MyFields(4) = "bar"

Or just look up Split() in the help files.



 
You put the file into a string. Then split that string into an array by the major divider. Then go through each element of the new array and split each one by the minor divider. Assuming that "|" is the major divider:

Dim strFileContents as string
Dim strMajorElements() as string
Dim strMinorElements() as string
Dim i as Integer

'get file contents
strFileContents = ....

'split the contents by "|"
strMajorElements = split(strFileContents,"|")

'go through each element
For i = 0 to Ubound(strMajorElements)
'split the element by space
strMinorElements = split(strMajorElements(i)," ")
'save the minor element to db (I'm assuming)
....
Next i

-Max
 
Or if each line represents a row you'd want to split it by the vbCrLf character first...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top