/*
  mi passive: generate

*!  VERSION 1.0.2  03jul2009

** This dialog box is called from the mi dialog

*/

VERSION 11.0
INCLUDE _std_medium
DEFINE _dlght 230
INCLUDE header
HELP hlp1, view("help mi_passive")
RESET res1

DIALOG main, tabtitle("Main")					///
	label("mi passive: generate - Generate and register passive variables")
	
BEGIN
  TEXT     tx_type	_lft	_top	_cwd1	.,		///
	label("Variable type:")
  COMBOBOX cb_type	@	_ss	_vnwd	.,		///
	label("Type") dropdownlist contents(type) 		///
	onselchangelist(main_type_actions) default(c(type))

  TEXT     tx_newname	_lft2	_top	_cwd3_1	.,		///
	label("Variable name:")
  EDIT     ed_newname	@	_ss	_vnwd	.,		///
	label("Variable name") nomemory

  GROUPBOX gb_contents	_lft	+35	_iwd	_ht7,		///
	label("Contents of variable")
  RADIO    rb_exp	_ilft	_ss	_ibwd	.,		///
	first label("Specify a value or an expression")		///
	onclickon(program check_values_exp)
  RADIO    rb_missing	@	+50	@	.,		///
	last label("Fill with missing data")			///
	onclickon(program check_values_exp)
  EXP      ex_exp	_indent2 -30	_inwd	.,		///
  	error("Specify a value or an expression") label("Create ...")
END

PROGRAM check_values_exp
BEGIN
	if main.rb_exp {
		call main.ex_exp.enable
		call script byifin_enable
	}
	else {
		call main.ex_exp.disable
		call script byifin_disable
	}
END

LIST main_type_actions
BEGIN
	program main_value_labels_enable
	program main_value_labels_enable
	program main_value_labels_enable
	program main_value_labels_enable
	program main_value_labels_enable
	script  main_value_labels_disable
END

INCLUDE byif
INCLUDE _type_list_all_string

PROGRAM my_by_output
BEGIN
	if sub.ck_by {
		require sub.vl_by
		put "by  " sub.vl_by ":"
	}
END

PROGRAM command
BEGIN
	put "mi passive: "
	put /program my_by_output " "
	
	put "generate "
	if ! main.cb_type.isdefault() {
		put " " main.cb_type " "
	}

	require main.ed_newname
	if ! main.ed_newname.isvalidname() {
		stopbox stop `"The variable name you specified is invalid."'
	}
	if main.ed_newname.isvarname() {
		stopbox stop `"The variable name you specified already exists."'
	}
	put main.ed_newname

	put " " "= "
	if main.rb_exp {
		require main.ex_exp
		put main.ex_exp
	}
	else {
		if main.cb_type.iseq("str") {
			put `""""'
		}
		else {
			put "."
		}
	}
	
	put " " /program if_output
END
