
! script name: vdatatable.d/insertrows
! var_topic: insert empty rows to a table

!A
!A NAME:
!A
!A 	Insert empty rows to a table	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	Insert empty rows to a table
!A
!B INSTRUCTIONS:
!B
!B      PICK ROW TO BE INSERTED BEFORE:
!B
!B      NUMBER OF ROWS INSERTED:
!B
!# see also - htdocs/help.d/datatables.htm

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

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DIM Table$[256]

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


ActivateUndo
Start:!
Element_loop:!
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK ROW TO BE INSERTED BEFORE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Table1) THEN Element_loop
Stat= EntityNameCheck(Table1,Table$)
T1= LastPickPara

R1=TableParaRow(Table1,T1)
C1=TableParaColumn(Table1,T1)

stat= SetInputFormat("n0=","")
Stat=SetEqualsValue(Nrows)
Nrows= GetValue("NUMBER OF ROWS INSERTED",Answer$)
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("insert rows")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Table1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Insert rows")
V1= FreeParameter("Number rows inserted",Nrows)
V2= FreeParameter("Inserted before row",R1)
Stat= InsertTableRows(Table$,V2,V1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Table1)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Element_loop

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