
! script name: hexajet.d/exporttable
! topic: export a table of data

!A
!A NAME:
!A
!A 	Export ASCII
!A
!A DESCRIPTION:
!A
!A	Exports a table of data as a tab separated ascii file.
!A
!B INSTRUCTIONS:
!B
!B 	EXPORT FILE NAME: Enter the name of the file.
!B
!B 	FILE EXISTS: OVERWRITE  Yes or No:
!B
!B 		Y - Enter Y to overwrite the existing file.
!B 		N - Enter N to enter a different file name.
!B
!C NOTE:
!C	
!C	The default location for exported ASCII tables is:	
!C
!C		/usr/weber/database/tables
!C
!# see also - htdocs/help.d/datatables.htm

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

DIM Answer$[256]
DIM A$[4096]
DIM B$[4096]
DIM Filename$[256]
DIM Destination$[256]
DIM Tab$[32]
DIM Lf$[32]
DIM Data$[32000]
DIM Sdevice$[256]
DIM Name$[256]
DIM Fline$[256]
DIM Field$[256]
DIM Descr$[256]
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)
Lf$= CHR$(10)


Sdevice$="/usr/weber/database/tables/Hexajet.d/"

Start:!
Filename$=""

Pick_table:stat= SetInputFormat("n4","")
Table1=PickEntity("PICK TABLE TO BE STORED")
IF (ExitScript(Destination$)) THEN Leave
IF NOT  ValidGeometry(Table1) THEN Pick_table

Ask_file:!
Filename$=""
Dir$="/usr/weber/database/tables/Hexajet.d/"
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO SAVE"
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("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$))

F_type= DoesFileExist(Filename$)
SELECT F_type
CASE 1
        Stat=SetInputFormat("a1",",Y,N,")
        Stat=GetValue("FILE EXISTS: OVERWRITE  Yes or No",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$= "N" THEN
                GOTO Ask_file
        END IF
CASE 2
        Stat=SetInputFormat("a1",",P,")
        Stat=GetValue("FILE NAME IS A DIRECTORY: Proceed ",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        GOTO Ask_file
END SELECT

Stat= RemoveFile(Filename$)
Stat= ExportTable(Table1,Filename$,Tab$,Lf$)

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