
! script name: hexajet.d/importtable
! topic: import a table of data

!A
!A NAME:
!A
!A 	Import Table
!A
!A DESCRIPTION:
!A	
!A	Imports a tab separated ascii list of data.
!A	Entries in a row are separated by tabs.
!A	Rows are separated by line feeds.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT EXTERNAL TABLE FILE: Select the table
!B 		to be imported.
!B
!B 	LOCATION ABS X,Y: Enter the location to
!B 		place the table.
!B
!# see also - htdocs/help.d/datatables.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: import table")

DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Name$[256]
DIM Filename$[256]
DIM Fline$[256]
DIM Field$[256]
DIM Descr$[256]
DIM Destination$[256]
DIM Tab$[32]
DIM Dir$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]

DEG

Tab$= CHR$(9)


Entry_text_height= GetDefault(WsTextHeight)
Entry_text_width= GetDefault(WsTextWidth)

Ask_file:!
Filename$=""
Dir$="/usr/weber/database/tables/Hexajet.d/"
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO OPEN"
Mask$="[A-Za-z0-9]*"
Mask$= "External Table Files (*.*)|*.*||"

Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$)
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT EXTERNAL TABLE FILE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerFileBox
Filename$=Answer$
IF NamedVarVal("save dirs",WsSystemVars,0) THEN V1=CreateVariable("datatables dir",WsSystemVars,PathNameDirectory(Answer$))

Center_point:Stat=SetInputFormat("n4","")
Pc=XyzInput("LOCATION",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Center_point

Name$= PathNameFile(Filename$)
Table1= ImportTable(Filename$,Pc,WsUpperLeft,Tab$)
Stat= DeleteEntity(Pc)
Stat= PlotEntity(Table1)
Stat= NameEntity(Table1,Name$)

ActivateUndo
Stat= AdvanceUndoNumber("import table")
Stat= AddItemToUndo(WsUBCreateMode,Table1)

Leave:!
Stat= DeleteEntity(Pc)
LowerFileBox
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
