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

How do I.. parse this MIF (text file) to strip only rqd filed

Status
Not open for further replies.

londonkiwi

Programmer
Sep 25, 2000
83
NZ
How do I to manipulate that following MIF (text) file from format A to format B

A
Version 300
Charset "WindowsLatin1"
Delimiter ","
CoordSys NonEarth Units "m" Bounds (1837078.087, 5698821.102) (3394395.121, 7522516.836)
Columns 1
ID Integer
Data

Pline 21
2628498.718203998 6612852.52640656
2628509.279149464 6612865.550329644
2628532.958933625 6612894.755904976
2628552.001806316 6612993.734255396
Pen (1,2,0)
Pline 3
2628594.068054039 6612435.989741675
2628623.059846602 6612381.050907688
2628673.672650207 6612307.309770684
Pen (1,2,0)


B

21 1001 1002 2628498 6612852
22 1003 1004 2628509 6612865
22 1005 1006 2628532 6612894
23 1007 1008 2628552 6612993

21 1009 1010 2628594 6612435
22 1011 1012 2628623 6612381
23 1013 1014 2628673 6612307

Where 21-23 are Interger 2, denoting start, middle and end of a line

1000 + are the "x" node and "y" nodes (Interger 6)

"xxxxxxx" and "xxxxxxx" are fixed length coordinates

The files are gnerally over 64k, and up to 600k.

How do you sugest I best go about this [sig][/sig]
 
What do you think about this:

Private Sub Command1_Click()

Dim lCounter As Long
Dim lLine As Long
Dim sLine As String
Dim sNewLine As String
Dim FileNumRead As Integer
Dim FileNumWrite As Integer
Dim lData1 As Long
Dim lData2 As Long
Dim i As Integer

Dim sFileName As String
sFileName = App.Path & "\readfile.mif"
Dim sNewFile As String
sNewFile = App.Path & "\newfile.mif"
FileNumRead = FreeFile

Open sFileName For Input As #FileNumRead
FileNumWrite = FreeFile
Open sNewFile For Output As #FileNumWrite

lCounter = 1001
lLine = 0

Do Until UCase(Left(sLine, 5)) = "PLINE" Or EOF(FileNumRead)
Line Input #FileNumRead, sLine
Loop
Line Input #FileNumRead, sLine ' get first line of data

Do Until EOF(FileNumRead)
' code here to process line of data, setting sData1 and sData2
If UCase(Left(Trim(sLine), 3)) <> &quot;PEN&quot; And UCase(Left(Trim(sLine), 5)) <> &quot;PLINE&quot; Then
i = 1
Do Until Mid(sLine, i, 1) = &quot;.&quot;
lData1 = lData1 & Mid(sLine, i, 1)
i = i + 1
Loop
Do Until Mid(sLine, i, 1) = &quot; &quot;
i = i + 1
Loop
i = i + 1
Do Until Mid(sLine, i, 1) = &quot;.&quot;
lData2 = lData2 & Mid(sLine, i, 1)
i = i + 1
Loop
Line Input #FileNumRead, sLine ' get next line to see what number to begin output with
If lLine = 0 Then
lLine = 21
Else
If IsNumeric(Left(sLine, 1)) Then
lLine = 22
Else
lLine = 23
End If
End If
Print #FileNumWrite, lLine & &quot; &quot; & lCounter & &quot; &quot; & lCounter + 1 & &quot; &quot; & lData1 & &quot; &quot; & lData2
If lLine = 23 Then
lLine = 0
End If
lCounter = lCounter + 2
lData1 = 0: lData2 = 0
Else
If lLine = 0 Then
Print #FileNumWrite, &quot;&quot;
lLine = -1
Else
lLine = 0
End If
Line Input #FileNumRead, sLine ' get next line to see what number to begin output with
End If
Loop

Close #FileNumRead
Close #FileNumWrite

MsgBox &quot;complete&quot;

End Sub

Simon [sig][/sig]
 
swilliams, that was great, thanks very much. I have used this and modified it already for another set of text files which req. some &quot;work&quot;. Can you suggest any worthwhile VB books or web sources to help me increase my VB knowledge

Thanks again, lk [sig][/sig]
 
I have only ever read one book on VB - Learn to Program Objects with VB6 - 2 years after starting to code in VB. The way I learnt how to do things was to ask questions - I used to work with someone who wrote a two year training course on VB4 (but I still never read that!) - and look at sample code. (that is why I felt it easier to post the code to do what you wanted, rather than give you hints and then you think 'What the hell do I do now?')
I will probably be slated for this, but I don't think there are any decent books, apart from lookup books, like VB Programmer's Guide to the Win32 API (SAMS) but to use these books you need to know what you are doing already - a bit of a paradox.
Keep practising, keep posting questions, keep looking in the help files - some of the sample code is useful - As a last thought, I do know that the MSDN / TechNet disks are a good reference.

Simon [sig][/sig]
 
Hiya,

I would tend to agree with you here, Simon. I learnt VB from scratch, with only a vague background in C, using only the MSDN help libraries and the partial books you get with it - the best of which has got to be &quot;Hardcore Visual Basic&quot;. I find that the only useful books are those you use for reference and, really, there's no substitute for playing about with code yourself and asking for help whenever you need it - I certainly have no problems helping people where I can now.

Help forums, like this one, I find very useful, too - excellent for picking up on things you just never knew before...

Cheerio,

Paul
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top