Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Stata8: Dialogs and macros


From   jlinhart@stata.com (Jean Marie Linhart, StataCorp.)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Stata8: Dialogs and macros
Date   Tue, 25 Mar 2003 11:08:35 -0600

"Plattner, Dankwart" <dankwart.plattner@kfw.de> wrote:

> I'm wondering whether one can use macros in S8-dialog windows. What
> I want to do is to manipulate the string shown by a dialog control
> (preferably, a text control, but it could also be an edit control)
> depending on the choice the user made in a radio control group or a
> FILE control.  Obviously that's not possible within the dialog,
> because one cannot use string functions there. Therefore I transfer
> the value associated with the radio/file controls to an ado-file,
> where the string is manipulated. But how to make the dialog
> understand the macros generated by the ado?  I tried the
> EDIT-control, but it accepts global macros only as a one-time
> default.  Any suggestions would be greatly appreciated!

I have to admit I am a bit mystified as to what you are actually
trying to do here.  It sounds as complicated as anything
I've written into the dialogs, and I wrote a lot!  
I'll take a stab at this anyhow. 

It seems to me you want to change text on a control based on
the state of a radio button or a file control.  I programmed
both of these things into a "sample dialog" which I will
include below.  You can change text via a trip through some
ado code too -- this is how you can access macros.  I programmed
this into the checkbox on the dialog  

I named my dialog dlgtest.dlg, and my ado program dlgtest.ado.
If you save these out as dlgtest.dlg and dlgtest.ado in your
adopath, you can invoke the dialog with -db dlgtest-.  Play
with it and have a look at the code.  I tried to include
one or two helpful comments to explain what was going on.

Please also note that whatever control is changed last governs
the label for tx_label.    

--- begin dlgtest.dlg --------------------------------------------
/*
  dlgtest - fiddle around with label changing
  
  VERSION 1.0.0  24mar2003

*/
VERSION 8.0

POSITION . . 400 300
OK ok1, label("OK")
CANCEL can1, label("Cancel")
SUBMIT sub1, label("Submit")
HELP hlp1, view("help dialog")
RESET res1

DIALOG main, label("dlgtest - fiddle with label changing") /*
		*/ tabtitle("Main")
BEGIN
  /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+*/ 
  TEXT     tx_file         10         10        380          .,		/*
  		*/label("Choose a file:")		
  FILE     fi_file         @         +20        @            .,		/*
  		*/label("Browse...") error("Saved graph")		/*
  		*/filter("Stata Graphs (*.gph)|*.gph|All Files (*.*)|*.*")/*
  		*/ defext(gph) onchange("script file_chg")

/* Since rb_one is on when the dialog starts up, it governs the 
 * initialization behavior of tx_label.
 */
  RADIO    rb_one          @         +40        @            .,		/*
  		*/label("Radio button one") first onclickon(program one_on)
  RADIO    rb_two          @         +20        @            .,		/*
  		*/label("Radio button two") last onclickon(program two_on)

  CHECKBOX ck_ado          @         +40        @            .,		/*
  		*/label("Change via ado code to:") onclickon(program ado_on)
  TEXT     tx_ado          @         +20        @            .,		/*
	*/label(`""Whatever text you want " followed by the filename"')
  TEXT     tx_ado2         @         +20        @            .,		/*
  	*/label("in the file chooser above.")

  TEXT     tx_label        @         +40        @            .,		/*
  		*/label("Change my label!")
END

PROGRAM ado_on
BEGIN
	put "dlgtest "
	put `""Whatever text you want ""'
	put main.fi_file
	stata
END

PROGRAM one_on
BEGIN
	call gaction main.tx_label.setlabel "Change me."
END

PROGRAM two_on
BEGIN
	call gaction main.tx_label.setlabel "Label according to Radio button two."
END

SCRIPT file_chg
BEGIN
	main.fi_file.withvalue main.tx_label.setlabel `"Label is file @"'
END

/* A public service announcement since this is just a test */
PROGRAM command
BEGIN
	put "Enjoy your commute, ride your bike to work!"
END

---end dlgtest.dlg -----------------------------------------------

---begin dlgtest.ado ---------------------------------------------
program define dlgtest
	version 8
	args string1 filename
	local newlabel "`string1' `filename'"
	/* this next uses the class system to set the label */
	.dlgtest_dlg.main.tx_label.setlabel `"`newlabel'"'
	/* the dlgtest_dlg names and defines the object 
                           -- dlgtest which is a dialog.
	   main is the name of the tab in dialog dlgtest
	   tx_label is the control in the main tab
	   setlabel is what I want to do to tx_label
	*/
end

---end dlgtest.ado -----------------------------------------------

Hope that helps!

--Jean Marie       with a bunch of help from     --Alan
jlinhart@stata.com                               ariley@stata.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index