/*
  stgen

*!  VERSION 1.1.1  01apr2005

*/

VERSION 9.0

INCLUDE _std_large
INCLUDE _ht200
INCLUDE header

HELP hlp1, view("help stgen")
RESET res1

DIALOG main, tabtitle("Main") 	///
	label("stgen - Generate variable reflecting entire histories")
BEGIN
  DEFINE  _x _xsetbu
  DEFINE  _y _top
  INCLUDE _bu_stset

  TEXT     tx_var         _lft      _ss       _cwd3_1    .,		///
		label("New variable name:")
  DEFINE y1 @y
  EDIT     ed_var         @         _ss       _vnwd      .,		///
		max(32)							///
		label("New variable name")

  TEXT     tx_fun         _lft      _ls       _comb3_1   .,		///
		label("Function:")
  DEFINE y2 @y
  COMBOBOX cb_fun         @         _ss       _vnwd      .,		///
		label("Function")					///
		dropdownlist contents("function")			///
		onselchangelist("fun_exp")
  TEXT     tx_exp         _lft3_2   y2        _vnr       .,		///
		label("Expression:")
  EXP      ex_exp         _lft3_2   _ss       _comb3_1   .,             ///
		label("Create...")					///
		error("Expression")
  TEXT     tx_type        @         y1        _vnwd      .,             ///
		label("New variable type:")
  COMBOBOX cb_type        @         _ss       _vnwd      .,             ///
		dropdownlist	                                        ///
		contents(type) default(c(type))
  COMBOBOX cb_type2       @         @         _vnwd      .,             ///
		dropdownlist	                                        ///
		contents(type) 						///
		default(c(type))
END

SCRIPT POSTINIT
BEGIN
	main.cb_type2.setvalue "byte"
END

INCLUDE _type_list_all

LIST function
BEGIN
	ever
	never
	always
	min
	max
	when
	when0
	count
	count0
	minage
	maxage
	avgage
	nfailures
	ngaps
	gaplen
	hasgap
END

LIST fun_exp
BEGIN
	script ex_onb
	script ex_onb
	script ex_onb
	script ex_onf
	script ex_onf
	script ex_onb
	script ex_onb
	script ex_onb
	script ex_onb
	script ex_onf
	script ex_onf
	script ex_onf
	script ex_off
	script ex_off
	script ex_off
	script ex_off
END

SCRIPT ex_onb
BEGIN
	script ex_on
	main.cb_type2.show
	main.cb_type.hide
	main.cb_type.disable
	main.cb_type2.enable
END

SCRIPT ex_onf
BEGIN
	script ex_on
	main.cb_type2.hide
	main.cb_type.show
	main.cb_type.enable
	main.cb_type2.disable
END


SCRIPT ex_off
BEGIN
	main.tx_exp.hide
	main.ex_exp.hide
	main.ex_exp.disable
	main.cb_type.disable
	main.cb_type.hide
	main.cb_type2.enable
	main.cb_type2.show
END

SCRIPT ex_on
BEGIN
	main.tx_exp.show
	main.ex_exp.show
	main.ex_exp.enable
END

PROGRAM command
BEGIN
	put "stgen "
	INCLUDE _type_pr
	if ! main.cb_type2.isdefault() {
		put main.cb_type2 " "
	}
	require main.ed_var
	put main.ed_var
	put " " "= "
	require main.cb_fun
	put main.cb_fun
	put "("
	if main.ex_exp.isvisible(){
		require main.ex_exp
		put main.ex_exp
	}
	put ")"
END
