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

RE: st: Stata8: Dialogs and macros

From   "Plattner, Dankwart" <>
To   "''" <>
Subject   RE: st: Stata8: Dialogs and macros
Date   Wed, 26 Mar 2003 21:07:19 +0100

Dear Jean-Marie,
>> Hope that helps!
This sure helped more than I had hoped for when posting my message! Thank
you very much!
I have now finished the dialog. On invocation of Stata, it asks for a
datafile to open and also opens a log file and a cmdlog with appropriate
filenames which depend on the name of the datafile + today's date (the user
may chose another logname). In addition, it checks for the file size and
sets the memory to the appropriate size before loading the datafile. Thank
you again very much!

Two questions and an observation remain:
Within the dialog, the trick is in the line

main.fi_file.withvalue main.tx_label.setlabel `"Label is file @"'

Are .withvalue and @ documented somewhere? I couldn't find them anywhere in
the manual. -findit withvalue- didn't give any results.
The observation: @ seems to be restricted to 64 characters (, therefore I
had to do this step also in the ado file - some path+file names are longer).
The second question: After the first call of the ado-file and the return to
the dialog, there is always a message:

. db ststartdpv8test
no variables defined

displayed. There's no such message later on (after the second, third, etc,
call). Do you have an idea what's the reason for this?
Dankwart Plattner

-----Original Message-----
From: []
Sent: Tuesday, March 25, 2003 6:09 PM
Subject: Re: st: Stata8: Dialogs and macros 

"Plattner, Dankwart" <> 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


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")
  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!")

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

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

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

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

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

---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 dlgtest.ado -----------------------------------------------

Hope that helps!

--Jean Marie       with a bunch of help from     --Alan                     
*   For searches and help try:
*   For searches and help try:

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