
! script name: vdatatable.d/enumeratecols
! var_topic: Label columns in a datatable numerically

!A
!A NAME:
!A
!A 	Tables: Enumerate Columns	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows columns in a datatable to be number.  The
!A	script will allow for starting and ending columns, a starting
!A	number and, an increment.  An ending column of 0 means to go
!A	to the end of the table.
!A
!B INSTRUCTIONS:
!B
!B 	PICK START ENTRY: Pick the position in the table for the first entry.
!B
!B 	PICK ENDING ENTRY: Pick the position in the table for the last entry.
!B
!B 	STARTING NUMBER: Enter the number to start the numbering process.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: enumerate columns ")

DIM Destination$[256],Answer$[256]
DIM Table$[256]
DIM A$[2]
DEG

A$= CHR$(10)

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Start:!
Element_loop:!
Stat= SetInputFormat("n4","")
Element1=PickEntity("PICK START ENTRY ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Element1) THEN Element_loop
T1= LastPickPara

Element2=PickEntity("PICK ENDING ENTRY ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Element2) THEN Element_loop
IF NOT AreEntitiesSame(Element1,Element2) THEN
	Stat= MessageStringBox(JoinStrings(A$,A$,"     TABLES CANNOT BE DIFFERENT      ",A$),"ERROR: TABLES DIFFERENT")
	GOTO Element_loop
END IF
T2= LastPickPara

R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)
R2=TableParaRow(Element2,T2)
C2=TableParaColumn(Element2,T2)
IF (R1<>R2) THEN
	Stat= MessageStringBox(JoinStrings(A$,A$,"     ENTRIES MUST BE IN THE SAME ROW      ",A$),"ERROR: ENTRIES IN DIFFERENT ROWS")
	GOTO Element_loop
END IF
Stat= SetInputFormat("n4","")
Startnum= GetValue("STARTING NUMBER ")
IF (ExitScript(Destination$)) THEN Leave
Stat= EntityNameCheck(Element1,Table$)

ActivateUndo
Stat= AdvanceUndoNumber("enumerate columns")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Enumerate columns ")
V1= FreeParameter("Row",R1)
V2= FreeParameter("Starting column",C1)
V3= FreeParameter("Ending column",C2)
V4= FreeParameter("Starting number",Startnum)
V5= FreeParameter("Increment",1)
V6= FreeParameter("Decimal places",0)
V7= StringConstant("")
V8= StringConstant("")
Stat= EnumerateColumns(Table$,V1,V2,V3,V4,V5,V6,V7,V8)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Element1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

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