Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to define a PREINIT or POSTINIT program in a dialogue box

    I have writing a dialogue box for a command called
    Code:
    reproot
    (see documentation for context). The only relevant context for this question is that this command requires a settings file and the dialogue box will help a user set up that file.

    Before opening the dialogue box, the command looks if the settings file exist, and if it does, it will prepopulate the dialogue box with that is already in the file. I have been able to generate the dialogue box, but I want to define a PREINIT or POSTINIT program has described in section 5.6 in this Stata manual: https://www.stata.com/manuals13/pdia...logprogramming. However, I have tried to defined it in all different ways I can imagine, but I always get a 198 error and I have not been able to find some more meaningful error message when running the command with tracing turned on.

    I know a reproducible example is almost always needed to give specific advice. But I am not sure how to best do so as without making it too complex. Happy to make an attempt if no one is able to point me to an example or other resource where I can see a general example of how this is done. For what it is worth, here is the current version of the dlg file, but I probably would have to give more context for the details to work: https://github.com/worldbank/repkit/...do/reproot.dlg. On line 84 I am trying to define the POSTINIT program. I am aware that the program is empty in that code, but I have tried with some basic code and I still get the same error. If I change
    Code:
    POSTINIT_PROGRAM test
    to
    Code:
    PROGRAM test
    but leave the program empty, I do not get a 198 error. But that might be different as a POSTINIT command is executed automatically.

    I have searched for other dlg files to see if I can find any example of POSTINI usage, but have not found any. So if anyone has an example like that I can look at to start with that might be the best option before I am trying to make a reproducible example.




  • #2
    Here is a minimal dialog that shows how to name these programs. I also include an example program that is associated with a tab.
    Code:
    VERSION 18.0
    
    INCLUDE _std_large
    
    INCLUDE header
    HELP hlp1, view(help contrast)
    RESET res1
    
    // preinit program called before any dialog controls are created
    PROGRAM PREINIT_PROGRAM
    BEGIN
        call main.ed_label.setvalue "preinit value"
    END
    
    // postinit program called once all dialog controls have been created
    PROGRAM POSTINIT_PROGRAM
    BEGIN
        call main.ed_label.setvalue "postinit value"
    END
    
    DIALOG main, title("Title") tabtitle("Main")
    BEGIN
        TEXT tx_label _lft _top _iwd ., label("text label:")
        EDIT ed_label @ _ms @ ., label("text label")
    END
    
    // postinit program called after opt tab controls have been created
    PROGRAM opt_POSTINIT_PROGRAM
    BEGIN
        call opt.ed_label.setvalue "option's postinit value"
    END
    
    DIALOG opt, tabtitle("Options")
    BEGIN
        TEXT tx_label _lft _top _iwd ., label("option label:")
        EDIT ed_label @ _ms @ ., label("option label")
    END

    Comment

    Working...
    X