473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

importing files - odd format

Hi all -

I have a file i am trying to import into an access database. The program I use (Blaise) exports it into a format like this (actual data is separated by quotation marks):

------------------------------------------------------------------------------
XX993395
DoctorsSeenBeforeMDDx.FamilyPractitioner
FOIC is a doctor so FOIC did a blood test on him.
------------------------------------------------------------------------------
XX993394
Therapies.PT.TherapyFrequency
He also gets range of motion on a daily basis with an associate at school.

------------------------------------------------------------------------------


These are comments that are separated by a line of dashed on the top and bottom. I want to extract the information between the dashes into 3 fields. the first would be an id (XX993395), then the question name (DoctorsSeenBeforeMDDx.FamilyPractitioner) and finally the comment for the question (FOIC is a doctor so FOIC did a blood test on him). All three fields will always be on one line. i do not want to import the dashes.

Thanks in advance for any help...i am sure there is an easy way, but i can't seem to find it!

Thanks
TJ
Aug 20 '07 #1
4 1760
MMcCarthy
14,534 Expert Mod 8TB
Hi TJ

There isn't an easy way to do this as it isn't a comma separated file or any other format that Access recognises. You will have to read this in line by line using VBA and validate each line.

To help you get started check out the following code.

Expand|Select|Wrap|Line Numbers
  1. Public Function readTextFile(ByVal fpath As String, ByVal filename As String) As String
  2. Dim fhandle As Integer
  3. Dim fline As String
  4.  
  5.     ' open the text file to be read
  6.     fhandle1 = FreeFile()
  7.     Open fpath & filename For Input Access Read Lock Write As #fhandle1
  8.  
  9.     Do While Not EOF(fhandle1) ' loop until you reach the end of the file.
  10.  
  11.         Line Input #fhandle1, fline
  12.         fline = Trim(fline)  ' cut off spaces
  13.  
  14.         ' you will have to add code here to check for the appropriate value and
  15.         ' I would suggest you create a comma separated string for each record and
  16.         ' then add code to add it to the table once the record is complete
  17.  
  18.     Loop
  19.  
  20.     Close #fhandle
  21.  
  22.     readTextFile = dateValue
  23.  
  24. End Function
  25.  
Aug 21 '07 #2
Thanks. I am not sure how i create a comma separated string for each record.

I know i want it to say if line = "------" then skip to the next line and read in that line, follow that by a comma, then read the next line, comma, next line then start a new record and continue as stated, but i am not sure of the correct context i would use for VB.

thanks
TJ

Hi TJ

There isn't an easy way to do this as it isn't a comma separated file or any other format that Access recognises. You will have to read this in line by line using VBA and validate each line.

To help you get started check out the following code.

Expand|Select|Wrap|Line Numbers
  1. Public Function readTextFile(ByVal fpath As String, ByVal filename As String) As String
  2. Dim fhandle As Integer
  3. Dim fline As String
  4.  
  5.     ' open the text file to be read
  6.     fhandle1 = FreeFile()
  7.     Open fpath & filename For Input Access Read Lock Write As #fhandle1
  8.  
  9.     Do While Not EOF(fhandle1) ' loop until you reach the end of the file.
  10.  
  11.         Line Input #fhandle1, fline
  12.         fline = Trim(fline)  ' cut off spaces
  13.  
  14.         ' you will have to add code here to check for the appropriate value and
  15.         ' I would suggest you create a comma separated string for each record and
  16.         ' then add code to add it to the table once the record is complete
  17.  
  18.     Loop
  19.  
  20.     Close #fhandle
  21.  
  22.     readTextFile = dateValue
  23.  
  24. End Function
  25.  
Aug 23 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Thanks. I am not sure how i create a comma separated string for each record.

I know i want it to say if line = "------" then skip to the next line and read in that line, follow that by a comma, then read the next line, comma, next line then start a new record and continue as stated, but i am not sure of the correct context i would use for VB.

thanks
TJ
Create a string variable to hold the comma separated data.
fline is a string so you need an IF statement something like
Expand|Select|Wrap|Line Numbers
  1. Dim strCSV As String
  2.  
  3. If fline LIKE "----*"  OR fline = "" Then
  4.  ' do nothing
  5. Else
  6.     strCSV = strCSV & "," & fline
  7. End If
Aug 24 '07 #4
missinglinq
3,532 Expert 2GB
You might want to take a look at this white paper. It deals specifically with the Blaise API vis a vis intereacting with COM compatible languages such as Access/Excel VBA as well as VB6 and C/C++.

Using the Blaise API Objects Library

Linq ;0)>
Aug 24 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andreas Emmert | last post by:
Hi there, I'm trying to import a csv file into my MySQL database. Unfortunately the number format for the price column is formatted in German style, i.e. XX,XX (decimals separated by comma not...
11
by: Jeff Wagner | last post by:
I am importing a file which contains a persons name (firstName, middleName, etc). If I define a function to do this, how can I use the variables outside of that function? Here is the code: ...
1
by: Thomas R. Hummel | last post by:
Hello, I am importing a file using BCP, with a format file. It is a fixed-width file, which I am importing into a table that has a column for each field in the file. The columns in my import...
12
by: expect | last post by:
What's the big deal with importing text files? I have a 70 MB file to import and it's been one problem after another. I used the copy command and it appears that it's just not possible. I finally...
3
by: rafeekb | last post by:
Importing V8.2 IXF files into V5.2 Hi All, As a regression step, I want to import the data (exported from the v8.2 client IXF format) into the v5.2 format. The source database server is on a...
4
by: rafeekb | last post by:
Hello All, Is there any way to export data in the IXF version 1 format from a DB2 v8.2 database ? The problem I am facing is to get the data from a v8.2 database which produces a version 2...
2
by: TheElectron707 | last post by:
Hi! I have a scenario in which i am importing a VERY LARGE database over the network. (Linking is not my solution). Now it takes many hours to import the complete database. I want that once the...
8
by: harry | last post by:
Hi Folks: I'm trying to do something that looks simple, but I can't make it work right. It's Access 2000 on a Win2000 computer. I create a database with 5 columbs. The data I need to import...
29
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using...
3
by: HistoricVFP | last post by:
Hello, I’ve been given the task of importing .dbf files from a very old version of Visual FoxPro (version 2.1) into Access (2003). When I import the data straight to Access it errors with: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.