*! version 1.0.3 ARB 12oct99 (STB-53: dm63.1) program define winset version 6.0 syntax [varlist], [LIst do] if _N == 0 { exit } if "`list'" == "list" { di in gr _n "WinShow settings for " in ye "$S_FN" parse "`varlist'", parse(" ") while "`1'" != "" { local vlab : var label `1' local len : char `1'[len] local ed : char `1'[noedit] local req : char `1'[req] local nomiss : char `1'[nomiss] local vtype : type `1' local vform : format `1' local vallab : value label `1' local range : char `1'[range] local def : char `1'[default] local ctype : char `1'[contype] if "`ed'" == "1" { local ed Yes } else { local ed No } if "`nomiss'" == "1" { local req Yes (and missing not allowed) } else if "`req'" == "1" { local req Yes } else { local req No } local contype edit box if "`ctype'" == "2" { local contype drop-down list } else if "`ctype'" == "3" { local contype check box } else if "`ctype'" == "4" { local contype radio button } local date 0 if substr("`vform'",1,2) == "%d" { local date 1 local vtype "`vtype', date" } local nostr = (substr("`vtype'",1,3) != "str") di in gr _dup(79) "-" di in ye "`1'" in gr " (`vtype') " in ye "`vlab'" _n if `nostr' & !`date' { if "`vallab'" == "" { di in gr "No value labels defined" } else { di in gr "This variable has value labels," label list `vallab' di } } di in gr "Control type: " in ye "`contype'" if "`contype'" == "edit box" | "`contype'" == "drop-down list" { di in gr "Control width: " in ye "`len'" di in gr "Must enter: " in ye "`req'" } if "`def'" != "" { di in gr "Default value: " in ye "`def'" _c if `date' & "`def'" != "todays date" { di in gr " (" in ye `vform' `def' in gr ")" } else { di } } di in gr "Editing prohibited: " in ye "`ed'" if "`range'" != "" { local rlo : word 1 of `range' local rhi : word 2 of `range' local rst : word 3 of `range' if "`rst'" != "" { local rst strictly } di in gr "Valid range: " in red "`rst' " in ye "`rlo'" in gr " to " in ye "`rhi'" _c if `date' { di in gr " (" in ye `vform' `rlo' in gr " to " in ye `vform' `rhi' in gr ")" } else { di } } mac shift } exit } if "`do'" == "do" { di in gr "* WinShow settings for $S_FN" parse "`varlist'", parse(" ") while "`1'" != "" { local vlab : var label `1' local vallab : value label `1' local len : char `1'[len] local ed : char `1'[noedit] local req : char `1'[req] local nomiss : char `1'[nomiss] local vtype : type `1' local vform : format `1' local range : char `1'[range] local def : char `1'[default] local ctype : char `1'[contype] di in gr _n "* `1'" di `"label variable `1' "`vlab'""' if !missing("`vallab'") { getvl `1' GWSval GWSvlen di `"label define `vallab' $GWSval"' di "label values `1' `vallab'" } di "format `1' `vform'" di "char `1'[len] `len'" if "`ed'" == "1" { di "char `1'[noedit] 1" } if "`nomiss'" == "1" { di "char `1'[nomiss] 1" } else if "`req'" == "1" { di "char `1'[req] 1" } if missing("`ctype'") { local ctype 1 } di "char `1'[contype] `ctype'" if !missing("`def'") { di "char `1'[def] `def'" } if !missing("`range'") { di "char `1'[range] `range'" } mac shift } macro drop GWS* exit } global GWSvarl "`varlist'" global GWSt1 "Choose a variable:" global GWSt2 "Variable label (30 max):" global GWSt3 "Valid range:" global GWSt4 "to" global GWSt6 "Width (characters):" global GWSt7 "Default:" global GWSt8 "Does not apply to string variable" global GWSt9 "Control type:" global GWSt10 "Value labels:" global GWSt11 "Edit box/drop-down list options:" global GWSretr "goretr" global GWScanc "exit 3000" global GWSclose "branch 1" global GWSback "branch 2" global GWShelp "whelp winset6" global GWSmod 0 /* Modified settings tripswitch */ chosvar cap exit 1 while _rc != 3000 & _rc !=0 { cap nois window dialog "WinShow settings" . . 224 180 if _rc == 3001 { retrieve } else if _rc == 3002 { chosvar } } if $GWSmod { window stopbox note "To make your settings permanent you" "should save your dataset now." } macro drop GWS* end * Branch from settings box: save settings and quit or go back to variable chooser program define branch version 6.0 args brcode saveset if `brcode'==2 { exit 3002 } exit 3000 end program define goretr version 6.0 if "$GWSvar" == "" { window stopbox stop "You must choose a variable first." } exit 3001 end program define chosvar version 6.0 window control static GWSt1 10 10 65 8 window control ssimple GWSvarl 10 18 60 120 GWSvar window control button "Retrieve current settings ->" 80 17 85 12 GWSretr default window control button "Close" 90 121 60 12 GWScanc escape end program define retrieve version 6.0 global GWSvlab : var label $GWSvar global GWSlen : char $GWSvar[len] global GWSed : char $GWSvar[noedit] global GWSreq : char $GWSvar[req] global GWSnomis : char $GWSvar[nomiss] global GWSdef : char $GWSvar[default] global GWSct : char $GWSvar[contype] if "$GWSct" == "" { global GWSct 1 } local vtype : type $GWSvar local vform : format $GWSvar global GWSdate global GWSdefr 1 if substr("`vform'",1,2) == "%d" { global GWSdate date local vtype "`vtype', date" if "$GWSdef"=="todays date" { global GWSdef global GWSdefr 2 } else if !missing("$GWSdef") { global GWSdef : display `vform' $GWSdef } } local nostr = (substr("`vtype'",1,3) != "str") local vallab : value label $GWSvar if "`vallab'" == "" { global GWSvalab "(None defined)" } else { getvl $GWSvar GWSvalab GWSlalen } local range : char $GWSvar[range] if missing("`range'") { global GWSrlo global GWSrhi global GWSrst } else { global GWSrlo : word 1 of `range' global GWSrhi : word 2 of `range' if "$GWSdate"=="date" { global GWSrlo : display `vform' $GWSrlo global GWSrhi : display `vform' $GWSrhi } global GWSrst : word 3 of `range' global GWSrst = ("$GWSrst" == "strict") } global GWSt5 "Settings for: $GWSvar (`vtype')" window control static GWSt5 10 5 115 8 window control static GWSt2 10 15 70 8 /* variable label */ window control edit 85 15 120 8 GWSvlab maxlen 30 window control static GWSt10 10 25 50 8 /* value labels */ window control edit 85 25 120 8 GWSvalab window control static GWSt9 10 40 55 7 /* control type */ window control radbegin "Edit box" 10 50 55 7 GWSct window control radio "Drop-down list" 10 60 55 7 GWSct window control radio "Check box" 10 70 55 7 GWSct window control radend "Radio buttons" 10 80 55 7 GWSct window control static GWSt11 85 43 130 72 blackframe /* edit box options */ window control static GWSt11 90 40 95 8 window control static GWSt6 90 55 58 8 window control edit 150 55 20 8 GWSlen window control check "Must enter?" 90 65 100 8 GWSreq window control check "Missing values prohibited?" 90 75 100 8 GWSnomis window control check "Cannot be edited?" 10 95 70 8 GWSed window control static GWSt3 90 85 50 7 /* range */ if `nostr' { window control edit 90 95 40 8 GWSrlo window control static GWSt4 133 95 8 8 window control edit 142 95 40 8 GWSrhi window control check "Never accept values outside range?" 90 105 120 8 GWSrst } else { window control static GWSt8 90 95 60 16 } window control static GWSt7 10 110 50 7 /* default */ if "$GWSdate"=="date" { window control radbegin "Value:" 10 120 30 7 GWSdefr window control radend "Today's date" 10 130 50 7 GWSdefr window control edit 50 120 50 8 GWSdef } else { window control edit 10 120 50 8 GWSdef } window control button "<- Back" 35 150 40 12 GWSback window control button "Close" 80 150 60 12 GWSclose escape window control button "Help" 145 150 40 12 GWShelp end program define saveset version 6.0 local vtype : type $GWSvar local str = (substr("`vtype'",1,3) == "str") * Range if "$GWSrlo" != "" | "$GWSrhi" != "" { if `str' { window stopbox stop "You cannot specify a range for a string variable." } } if "$GWSrst" == "1" & ("$GWSrlo" == "" | "$GWSrhi" == "") { window stopbox stop "You have not specified a range." } if ("$GWSrlo" == "" & "$GWSrhi" != "") | ("$GWSrlo" != "" & "$GWSrhi" == "") { window stopbox stop "You must specify both limits of the range." } if "$GWSrlo" != "" & "$GWSrhi" != "" { cap confirm number $GWSrlo if "$GWSdate"=="date" & _rc { local rlo = date("$GWSrlo","dmy") local mesg "N.B. dates should be entered in dmy format including the century." cap confirm number `rlo' } if _rc { window stopbox stop "Lower range limit not valid." "`mesg'" } cap confirm number $GWSrhi if "$GWSdate"=="date" & _rc { local rhi = date("$GWSrhi","dmy") local mesg "N.B. dates should be entered in dmy format including the century." cap confirm number `rhi' } if _rc { window stopbox stop "Upper range limit not valid." "`mesg'" } if "$GWSrst" == "1" { local rtype "strict" } if "$GWSdate"=="date" { if `rlo' > `rhi' { window stopbox stop "The lower limit of your range exceeds the upper limit." } char $GWSvar[range] "`rlo' `rhi' `rtype'" } else { if $GWSrlo > $GWSrhi { window stopbox stop "The lower limit of your range exceeds the upper limit." } char $GWSvar[range] "$GWSrlo $GWSrhi `rtype'" } } else { char $GWSvar[range] } * Default if $GWSdefr==2 { char $GWSvar[default] todays date } else if !missing("$GWSdef") & `str' == 0 { cap confirm number $GWSdef if "$GWSdate"=="date" & _rc { local defdate=date("$GWSdef","dmy") local mesg "N.B. dates should be entered in dmy format including the century." cap confirm number `defdate' } if _rc { window stopbox stop "Default value not valid - $GWSvar is numeric." "`mesg'" } if "$GWSdate"=="date" { char $GWSvar[default] `defdate' } else { char $GWSvar[default] $GWSdef } } else { char $GWSvar[default] $GWSdef } * Value labels if `"$GWSvalab"'!="(None defined)" { local vallab : value label $GWSvar label define `vallab' $GWSvalab, modify } label var $GWSvar "$GWSvlab" char $GWSvar[len] $GWSlen char $GWSvar[noedit] $GWSed char $GWSvar[nomiss] $GWSnomis char $GWSvar[req] $GWSreq char $GWSvar[contype] $GWSct global GWSmod 1 * window stopbox note "The WinShow settings for the $GWSvar" "variable have been saved." end * Get value label list of variable `1' and put into global `2' * Put maximum label length (in characters) into global `3' program define getvl version 6.0 global `2' global `3' 0 local vlab : value label `1' if missing("`vlab'") { di in red _n "`1' not labeled - cannot use drop down list." macro drop GWS* exit 182 } tempfile values qui { label save `vlab' using `values' preserve infix str s 1-80 using `values', clear } local i 1 while `i' <= _N { local si = s[`i'] local sin : word 4 of `si' local sit : word 5 of `si' local sil = length("`sit'") if `sil' > ${`3'} { global `3' `sil' } global `2' `"${`2'}`sin' `"`sit'"' "' local i = `i' + 1 } restore end