
! script name: vdatatable.d/numrowsvar
! var_topic: make variable for number of rows in a table

!A
!A NAME:
!A
!A 	Variable: Number of table rows
!A
!A DESCRIPTION:
!A
!A 	This script makes a variable that represents the number of rows
!A	in a table.
!A
!B INSTRUCTIONS:
!B
!B 	VARIABLE NAME: Enter the variable name.
!B
!B 	INVALID VARIABLE NAME: Name input was invalid choose new variable.
!B
!B	PICK TABLE: Graphically choose the table to use.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: table rows variable")

DIM Answer$[256]
DIM Name$[256]
DIM Destination$[256]
DIM Element$[256]
DEG

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

DeActivateUndo
Name_loop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("VARIABLE NAME",Answer$)
IF ExitScript(Destination$) THEN Leave
Name$=Answer$
IF NOT ValidVariableName(Name$)	THEN
	Stat=SetInputFormat("a99","")
	Stat=GetValue("INVALID VARIABLE NAME, Proceed",Answer$)
	IF ExitScript(Destination$) THEN Leave
	GOTO Name_loop
END IF

Pick_loop:!
Stat= SetInputFormat("n4","")
Element1=PickEntity("PICK TABLE ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Element1) THEN Pick_loop
T1= LastPickPara
Stat= EntityNameCheck(Element1,Element$)

RecordFunctionOn
Stat=RecordDescr("VARIABLE: table rows")
V1=NumericVariable(Name$,WsVariationVars,NumberTableRows(Element$))
Stat=SetVariableDescr(V1,"Variable: rows in table ")
RecordFunctionOff
CloseVarRecord

GOTO Name_loop

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

