home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 11
/
BUGCD1998_02.ISO
/
aplic
/
turbocad
/
tcw.z
/
Impoint.bas
< prev
next >
Wrap
BASIC Source File
|
1997-05-05
|
3KB
|
108 lines
' This sample program is an example of how to do custom file IO from
' TurboCAD. We will build graphics from the vertices in the table.
'
' Author : Mike Cartwright, Tamara Cartwright (updated to 4.0 interface)
' Date : 01/08/96, 03/08/97
'
'Constants
Global Const GK_GRAPHIC = 11
Global Const NULL = 0
' File I/O constants
Global Const EOFILE = -1
Sub Main ()
Dim FileName As String
Dim LineBuffer As String
Dim g As Long
Dim v As Long
Dim vi As Long
Dim fh As Long
Dim dActive As Long
Dim x As Double
Dim y As Double
Dim z As Double
Dim Part As String
Dim PartX As String
Dim PartY As String
Dim PartZ As String
Dim Delim As String
Dim Pos As Integer
' Check for valid drawing
dActive = TCWDrawingActive ()
If dActive = NULL Then
MsgBox "Program requires active drawing."
' Terminate the program
Stop
End If
vi = 0
g = NULL
' Delimiter for record fields in the input text file
Delim = Chr$(9)
' Get the name of the input file
FileName = InputBox("Type in the filename to import from")
If (FileName <> "") Then
' Open input text file.
fh = TCWOpenInput(FileName)
' Read lines from the input file and brake them down
' to numeric values
vi = 0
while (TCWReadInput(fh, LineBuffer) <> EOFILE)
' Graphic separator
if LineBuffer = "" Then
if ((g <> NULL) And (vi > 0)) Then
TCWGraphicAppend NULL, g
TCWGraphicDraw g, 0
g = NULL
End If
vi = 0
End If
if (LineBuffer <> "") Then
' find the first delimiters position in Line
Pos = InStr(1, LineBuffer, Delim, 0)
' Let's remove the index part
Part = Right$(LineBuffer, Len(LineBuffer) - Pos)
' Let's find position of the second delimiter
Pos = InStr(1, Part, Delim, 0)
' Let's extract the frist number
PartX = Left$(Part, Pos-1)
x = Val(PartX)
Part = Right$(Part, Len(Part) - Pos)
' Let's find the position of the third delimiter
Pos = InStr(1, Part, Delim, 0)
PartY = Left$(Part, Pos-1)
y = Val(PartY)
PartZ = Right$(Part, Len(Part) - Pos)
z = Val(PartZ)
' Add vertex (x, y, z) to the graphic g
If vi = 0 Then
g = TCWGraphicCreate(GK_GRAPHIC, "")
End If
If g <> NULL Then
TCWGraphicXYZAdd g, x, y, z
End If
vi = vi + 1
End If
wend
' If anything is left out we need to add to the drawing
' now.
if ((g <> NULL) And (vi > 0)) Then
TCWGraphicAppend NULL, g
End If
TCWCloseInput fh
End If
End Sub