Announcement

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

  • Custom dialog box: Appending content from one EDIT field to another

    Hello everyone.

    I am programming a custom dialog box for Stata. This dialog box contains two EDIT fields (main.ed_1 and main.ed_2) and a button that calls a program named "append." I would like the program to take the content of main.ed_2 and add it to the content of main.ed_1 so that if main.ed_1 contains "this" and main.ed_2 contains "that", when the button is pressed, the content of main.ed_1 becomes "thisthat".

    For that, I wrote the program as follows:

    PROGRAM append
    BEGIN
    call main.ed_1.append main.ed_2
    END

    However, this literally adds "main.ed_2" instead of the string that main.ed_2 contains. I tried using `main.ed_2', but it doesn't work. What am I doing wrong?

  • #2
    Without a working example it is hard to verify any advice we give you will work.

    Here is what I came up with based on the description.
    Code:
    VERSION 18.0
    INCLUDE _std_medium
    DEFINE _dlght 160
    INCLUDE header
    
    HELP hlp1, view("help dialog")
    RESET res1
    
    DIALOG main, title(resource COLLECT_SET_DLG_TITLE)
    BEGIN
        TEXT tx_1 _lft _top _iwd ., label("Text 1:")
        EDIT ed_1 @ _ss @ ., label("Text 1") default("this")
    
        TEXT tx_2 _lft _ls _iwd ., label("Text 2:")
        EDIT ed_2 @ _ss @ ., label("Text 2") default("that")
    
        BUTTON bu_append _lft _xls _setbuwd ., ///
            label("Append") ///
            onpush(program append)
    END
    
    PROGRAM append
    BEGIN
        call main.ed_2.withvalue main.ed_1.append "@"
    END

    Comment


    • #3


      Thank you, Jeff. The program you wrote works perfectly and solves my problem!

      Before writing my post, I made sure to thoroughly read the "dialog programming" PDF manual (https://www.stata.com/manuals13/pdialogprogramming.pdf). However, I didn't find anything about "withvalue" as a member function of an EDIT input control.

      Is there any manual or documentation on this that I should have been aware of before posting?

      Comment


      • #4
        I believe .withvalue was never really documented, but it is mentioned in an example. It should have been documented like .append and .setvalue.

        BTW, you are referencing documentation for Stata 13, the current documentation is at https://www.stata.com/manuals/pdialogprogramming.pdf.

        I will try to get this documented in a future update to Stata 18.

        Comment

        Working...
        X