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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a txt file as shown below wh

Status
Not open for further replies.

CMPaccess

Technical User
Dec 18, 2003
52
AU
I have a txt file as shown below which is automatically created via AutoCAD. What I want to do is then extract certain information from the txt into my access table.

This is a sample of the txt file :-

# This file was automatically generated by ARX Module
# written at: 16 December 2003 17:30:03
# sActualName = C:\SFLY_S-_SK05_SP---.dwg

DATA_FORMAT 1.0
GENERATORARX

START GENERAL

# Basic info about drawing
BASENAME SFLY_S-_SK05_SP---.dwg
DWGDIR \\LOCAL:C:TBHANDLE 2B9
DWGTITLE1 General Arrangement Showing
DWGTITLE2 Indicative Structure for
DWGTITLE3 Travelator Bridges
DWGTITLE4
JOBTITLE1 on a Flyer
JOBTITLE2
JOBTITLE3
JOBTITLE4
DWGSTATUS Concept
JOBNUMBER 150042
JOBSUFFIX
TBSCALE 1:200
ORIGINATOR
ISSUEDATE
REVISION 1
DWGNUMBER S/SK05
DESCRIPTION

END GENERAL


The portion I need to extract are the attributes i.e

the scale = 1:200.

I have tried something using the mid function but it does not work as it only seems to read one line. Is it possible to specifically retreive information from any given line.??

The format of the txt file will never change.

Here was my attempt. Any help modifying this would be great.

Private Sub Command56_Click()
If IsNull([Path]) Then
MsgBox "You must set Drawing Directory in Path First and give filename for new record"
DoCmd.GoToControl "Path"
End If
Dim stfilename
Dim stPath
Dim temp$
Dim lookfor()

stfilename = ([CADFilename]) + "-dwg.din"
stPath = ([Path]) + "docinfo\"

Open stPath + stfilename For Input As #1
While Not EOF(1)
Line Input #1, temp$
Number1 = (Mid(temp$, 13, 28))
Number2 = (Mid(temp$, 51, 28))
Number3 = (Mid(temp$, 12, 10))
Number4 = (Mid(temp$, 12, 10))
Number5 = (Mid(temp$, 12, 4))
Number6 = (Mid(temp$, 12, 2))
Number7 = (Mid(temp$, 12, 10))
Wend
Me.DrawingTitle1 = Number1
Me.DrawingTitle2 = Number2
Me.DrawingTitle3 = Number3
Me.Status = Number4
Me.DScale = Number5
Me.Revision = Number6
Me.DrawingNumber = Number7
Close #1



End Sub

This theory works in that it will return a null to all the fields in my table. I just need it to pick out the correct text.
 
You are sort of 'on track' with your code, but are not recognising an important aspect of the program; the fact that you are applying the same logic for every line of the file. You need to differenciate the code for each line, so that for example, you only assign the DrawingTitle1 value when the associated data line is being processed.

Try the following revised code, with further explanations below:

Private Sub Command56_Click()
If IsNull([Path]) Then
MsgBox "You must set Drawing Directory in Path First and give filename for new record"
DoCmd.GoToControl "Path"
End If
Dim stfilename
Dim stPath
Dim temp$
Dim lookfor()
Dim RecordId$

stfilename = ([CADFilename]) + "-dwg.din"
stPath = ([Path]) + "docinfo\"

Open stPath + stfilename For Input As #1
While Not EOF(1)
Line Input #1, temp$
RecordId = left(temp$,9)
SELECT CASE RecordId
Case "DWGTITLE1"
Me.DrawingTitle1 = (Mid(temp$, 13, 28))
Case "DWGTITLE2"
Me.DrawingTitle2 = (Mid(temp$, 51, 28))
Case "DWGTITLE3"
Me.DrawingTitle3= (Mid(temp$, 12, 10))
Case "DWGSTATUS"
Me.Status = (Mid(temp$, 12, 10))
Case "TBSCALE "
Me.DScale = (Mid(temp$, 12, 4))
Case "REVISION "
Me.Revision = (Mid(temp$, 12, 2))
Case "DWGNUMBER"
Me.DrawingNumber = (Mid(temp$, 12, 10))
Case Else
End Select
Wend
Close #1

End Sub

Notes:

The SELECT CASE statement allows discriminatory processing of the input lines, depending on the 'RecordId', which is essentially defined as the first 9 characters of each line. In the code above, you look for selected RecordIds, and assign values to controls directly when these are found. Those records which are not important to you, essentially follow the 'Case Else' path where no code is present; they are thus essentially ignored.

Hope this helps,


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Steve,

Thanks alot, that works perfectly.

I had actually been toying around with the CASE solution but couldn't quite figure it out. I wasn't aware of the recordID part.

It's easy when you know how.!!!

cheers

chris

 
Steve,

One problem I have noticed.

If one of the CASE statements is Null the code breaks down.

Is there a simple way of adding and if Null statement.

thanks

Chris
 
Chris,

This is probably happening because the fields in the table that the form is bound to do not allow NULL values and/or zero length values.

Go to the associated table definition, and set the field properties for each of the bound controls on the form as follows:

Required: No
Allow Zero Length: Yes

This will hopefully solve the problem.

Let me know,


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Steve,

Thanks, you were spot on again.

I actually thought it might be something like that but thought that was too obvious. So I was trying to find a more technical solution.

Thanks again for your help.

Cheers

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top