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

Retrieving Lines from Text File

Status
Not open for further replies.

CMPaccess

Technical User
Dec 18, 2003
52
AU
I have a text file like this.

# This file was automatically generated by MicroStation v8

DATA_FORMAT 2.1
GENERATOR MicroStation_v8
DINLASTUPDATED 2004-02-13 15:51:50

START GENERAL
BASENAME S11-00
DOCDIR G:\81120\STR\
DOCTYPE MicroStation
AUTHOR cbs
DOCFILEREF S11-00
DOCSTATUS PRELIMINARY - NOT FOR CONSTRUCTION
DOCTITLE COLUMN SCHEDULE | AND DETAILS
JOBNUMBER 81120
JOBTITLE Canberra Theatre Link | Redevelopment
REVISION A
TBSCALE 1:100
NOTES Model file
END GENERAL

I have the code written as

Open stPath + stfilename For Input As #1
While Not EOF(1)
Line Input #1, temp$
RecordId = Left(temp$, 9)
Select Case RecordId
Case "DOCTITLE"
Me.DrawingTitle1 = (Mid(temp$, 12, 50))
Case "DOCSTATUS"
Me.Status = (Mid(temp$, 12, 28))
Case "TBSCALE"
Me.DScale = (Mid(temp$, 12, 28))
Case "REVISION"
Me.Revision = (Mid(temp$, 12, 28))
Case "DOCFILEREF"
Me.DrawingNumber = (Mid(temp$, 12, 28))
Case Else
End Select

Now this worked on a previous text file that I had but with this one it only returns the "DOCSTATUS"

I believe it is something connected to
RecordId = Left(temp$, 9) with 9 being the factor but i cannot figure it out!!

Any clues to put this right.

Thanks in advance
 
Your spot on with your assumption, your code takes the first 9 characters of the line and tried to match it against everything in the Case statement.

The only one that is nine characters long is 'DOCSTATUS'

to fix this problem you should use:

Code:
RecordId = Left(temp$, (InStr(1, temp$, chr(160))-1))

Which will read everything until a space is encountered and should work for all your required fields.

----------------------------------------
My doctor says that I have a malformed public duty gland and a natural deficiency in moral fibre and that I'm therefore excused from saving universes.
----------------------------------------
 
Mute 101,

Thanks for that I will give that a try.

I eventually reallise where I had gone wrong. I had moved the " to the end of the Case statement instead of leaving it at the 10th space. i.e.

"docinfo"
"doc "
That works as well.

I have another quick question for you though if you don't mind !!!

I'm trying to use the Split function on the DOCTITLE above.
The line i'm trying to split reads
DOCTITLE COLUMN SCHEDULE | AND DETAILS

I'm going along the lines of

Case "DOCTITLE "
FullTitle = (Mid(temp$, 12))
Titleparts() = Split(FullTitle, [chr(124)], [])
Me.DrawingTitle1 = Titleparts(1)
Me.DrawingTitle2 = Titleparts(2)
Me.DrawingTitle3 = Titleparts(3)

But I cannot get it to recognise the "|" symbol as the split.

Any ideas ??

Thanks again though
 
Not sure why your putting those square brackets in, all you need is;

Code:
titleParts = Split(FullTitle, Chr(124), -1, 1)
Me.DrawingTitle1 = Titleparts(0)
Me.DrawingTitle2 = Titleparts(1)

Remember that collections (arrays) are zero based so the first value is found in 'Titleparts(0)' and that your string will only be split into two parts not three.

Hope that helps.
Simon

----------------------------------------
My doctor says that I have a malformed public duty gland and a natural deficiency in moral fibre and that I'm therefore excused from saving universes.
----------------------------------------
 
Simon,

thanks but that now returns a "Runtime Error 13 type Mismatch" at that line.

The reason I was putting the boxes in was I was trying every possible combination. Still could not get it to work.

The reason that there are 3 Titles is because the text files maybe differnt. eg another one could read

DOCTITLE COLUMN SCHEDULE | PLAN | AND DETAILS

Any ideas where Its going wrong ??

Thanks

Chris
 
Try this:
Dim titleParts As Variant
titleParts = Split(FullTitle, Chr(124))
Me.DrawingTitle1 = Titleparts(0)
If UBound(Titleparts) >= 1 Then Me.DrawingTitle2 = Titleparts(1)
If UBound(Titleparts) >= 2 Then Me.DrawingTitle3 = Titleparts(2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Spot on PHV, the problem stemmed from your variable you were trying to put the split strings into. He/she (sorry PHV I just don't know) also shows you how to deal with a variable number of strings in the collection.

----------------------------------------
My doctor says that I have a malformed public duty gland and a natural deficiency in moral fibre and that I'm therefore excused from saving universes.
----------------------------------------
 
thanks people.

PHV's solution works like a dream.


thanks again.

much appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top