
! script name: vdatatable.d/indexrows
! var_topic: Label rows in a datatable numerically

!A
!A NAME:
!A
!A 	Tables: Index Rows 		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows rows in a datatable to be indexed with letters.
!A	The script will allow for starting and ending rows and a starting
!A	letter sequence.  An ending row of 0 means to go to the end of the
!A	table.  Letter sequences go (upper or lower case):
!A	      A,B,C ..... Y,Z,AA,BB ........ YY,ZZ,AAA,BBB .... ZZZ.
!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 LETTER SEQUENCE: Enter the letter sequence to put into the
!B	     table. The letters must all be the same.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: index rows ")

DIM Destination$[256],Answer$[256]
DIM Table$[256]
DIM A$[2],B$[32]
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 (C1<>C2) THEN
	Stat= MessageStringBox(JoinStrings(A$,A$,"     ENTRIES MUST BE IN THE SAME COLUMN      ",A$),"ERROR: ENTRIES IN DIFFERENT COLUMNS")
	GOTO Element_loop
END IF

New_letter:!
Stat= SetInputFormat("a99","")
Stat= GetValue("STARTING LETTER SEQUENCE ",B$)
IF (ExitScript(Destination$)) THEN Leave
FOR K= 1 TO LEN(B$)
	IF B$[K,K]<>B$[1,1] THEN New_letter
NEXT K
Stat= EntityNameCheck(Element1,Table$)

ActivateUndo
Stat= AdvanceUndoNumber("index rows")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Index rows ")
V1= FreeParameter("Column",C1)
V2= FreeParameter("Starting row",R1)
V3= FreeParameter("Ending row",R2)
V4= StringConstant(B$)
V5= StringConstant("")
V6= StringConstant("")
Stat= IndexTableRows(Table$,V1,V2,V3,V4,V5,V6)
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
