Importing Text

B

Bre-x

Hi, I need some help importing a tool list from Mastercam. Here is the Text
File

# = 1
Type = Center Drill
Tool name = 1/8 CENTERDRILL
Diameter = 0.125000
Rad. Type = None
Cor. rad. = 0.000000
Threads = 0.000000

# = 2
Type = Center Drill
Tool name = 1/4 CENTERDRILL
Diameter = 0.250000

# = 3
Type = Center Drill
Tool name = 1/2 CENTERDRILL
Diameter = 0.500000
Cor. rad. = 0.000000

..............etc, etc, etc

I need to go into each "# =" occurrence then import into a table

TID, Type, Tool, Diameter
1, Center Drill, 1/8 CENTERDRILL, 0.125000
2, Center Drill, 1/4 CENTERDRILL, 0.250000
3, Center Drill, 1/2 CENTERDRILL, 0.500000

The "Type, Tool, and Diameter" are always the first 3 Lines After the Tool
ID: " # = "


Thank you all,

Bre-x
 
B

Bre-x

Thanks!!

Dim strFile As String
Dim intFile As Integer
Dim strInput As String
Dim db As Database
Dim rs As Recordset

strFile = "N:\1CNC\TOOLLST.TXT"
intFile = FreeFile
Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset("tblTool")
Open strFile For Input As intFile
Do
Line Input #intFile, strInput
If Left(strInput, 3) = "# =" Then
rs.AddNew
rs!ToolNumber = Mid(strInput, 4)
ElseIf Left(strInput, 4) = "Type" Then
rs!ToolType = Mid(strInput, 8)
ElseIf Left(strInput, 9) = "Tool name" Then
rs!ToolName = Trim(Mid(strInput, 12))
ElseIf Left(strInput, 8) = "Diameter" Then
rs!Diameter = Trim(Mid(strInput, 11))
ElseIf Left(strInput, 8) = "Material" Then
rs!mat = Trim(Mid(strInput, 11))
rs.Update
End If
Loop Until EOF(intFile)

rs.Close
Set rs = Nothing
Set db = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top