element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Chat (English) ULP script dlgAccept()
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Autodesk EAGLE to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 8 replies
  • Subscribers 173 subscribers
  • Views 765 views
  • Users 0 members are here
Related

ULP script dlgAccept()

ameliaamelia
ameliaamelia over 13 years ago

In the following variable length dialog

 

int XXX;

int YYY;

XXX = dlgDialog ("Menu"{

for (YYY = 1; YYY < 5; YYY++)

{

  dlgCell .... dlgAccept(YYY);

}

 

YYY contains always 5.

 

It seams that dlgAccept "accepts" only constants value such as 1, 2, 3 ....not a variable, or I'm wrong?

 

EAGLE HELP: 

void dlgAccept([ int Result ]);

 

amelia

  • Sign in to reply
  • Cancel
  • Former Member
    Former Member over 13 years ago

    ameliaamelia wrote:

    In the following variable length dialog

     

    int XXX;

    int YYY;

    XXX = dlgDialog ("Menu"{

    for (YYY = 1; YYY < 5; YYY)

    {

    + dlgCell .... dlgAccept(YYY);+

    }

     

    YYY contains always 5.

     

    It seams that dlgAccept "accepts" only constants value such as 1, 2,

    3 ....not a variable, or I'm wrong?

     

    +EAGLE HELP: +

    void dlgAccept();

     

    amelia

     

    Using v5.12, dlgAccept() does accept a variable. The ULP below displays a

    MessageBox result of 66 from the MYexit variable.

    HTH

    Warren

     

     

    int acceptexit = 66;

    int MYexit;

    string result;

    MYexit = dlgDialog("Accept-Test"){

     

            dlgPushButton("+OK"){

             dlgAccept(acceptexit);

            }

     

            dlgPushButton("-Cancel"){

             dlgReject();

            }

    };

    sprintf(result,"%u",MYexit);

    dlgMessageBox(result);

     

     

     

    --

    Viewed / responded via the newsgroup at

    news.cadsoft.de

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ameliaamelia
    ameliaamelia over 13 years ago in reply to Former Member

    Yes, if you use a single statement, but try using the loop as in my example or :

     

    int YYY;

    ...

    YYY = 1;

    dlgCell .... dlgAccept(YYY);

    YYY = 2;

    dlgCell .... dlgAccept(YYY);

     

    The returned Accept() value is always the last specified on the variable, in the upper example = 2.

     

    Amelia.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to ameliaamelia

    ameliaamelia wrote:

    Yes, if you use a single statement, but try using the loop as in my

    example or :

     

    int YYY;

    ...

    YYY = 1;

    dlgCell .... dlgAccept(YYY);

    YYY = 2;

    dlgCell .... dlgAccept(YYY);

     

    The returned Accept() value is always the last specified on the

    variable, in the upper example = 2.

     

    Amelia.

     

     

    OK you accept variables can be used and not just constants as you initially

    queried.

     

    So your new need for understanding is "why does the returned value == 2 when

    I wish to close and exit the dialog at the point when YYY==1"?

     

    As per the HELP the code after the dlgAccept() is run. So YYY is changing to

    2 before the Dialog closes so will always be 2.

    Structure / bracket your code to prevent this effect.

     

    If you are still having a problem. provide some real code so you can be

    shown where you are going wrong, if thats the case.

     

    HTH

    Warren

     

     

     

    --

    Viewed / responded via the newsgroup at

    news.cadsoft.de

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to Former Member

    Again, two complete examples:

     

    ///////////////////////////////// 1- direct definition with constant //////////////////      

    int select_dlg;

     

           

    select_dlg = dlgDialog("XXXX")

            

    {

             

    dlgGridLayout

              

    {

               

    dlgCell(0,0) dlgLabel(E.name);

               

    dlgCell(0,1) dlgLabel(E.value);

               

    dlgCell(0,2) dlgLabel(E.package.name);

               

    dlgCell(1,0,1,2) dlgPushButton("Text1") dlgAccept(0);

               

    dlgCell(2,0,2,2) dlgPushButton("Text2") dlgAccept(1);

               

    dlgCell(3,0,3,2) dlgPushButton("Text3") dlgAccept(2);

               

    dlgCell(4,0,4,2) dlgPushButton("Text4") dlgAccept(3);

               

    dlgCell(5,0,5,2) dlgPushButton("Text5") dlgAccept(4);

               

    dlgCell(6,0,6,2) dlgPushButton("Text6") dlgAccept(5);

               

    dlgCell(6,0,6,2) dlgPushButton("Text7") dlgAccept(6);

               

    dlgCell(6,0,6,2) dlgPushButton("Text8") dlgAccept(7);

               

    dlgCell(7,0,7,2) dlgPushButton("+Text9") dlgAccept(8);

              

    }

            

    };

               

    ///////////////////////////////// 2- using a loop with variable ///////////////////////

    int MAX_TEXT = 9;

    string selects[] =

    {

      

    "Text1",

      

    "Text2",

      

    "Text3",

      

    "Text4",

      

    "Text5",

      

    "Text6",

      

    "Text7",

      

    "Text8",

      

    "Text9"

    };

     

    int select_dlg;

    int select_num;

     

           

    select_dlg = dlgDialog("XXXX")

            

    {

             

    dlgGridLayout

              

    {

               

    dlgCell(0,0) dlgLabel(E.name);

               

    dlgCell(0,1) dlgLabel(E.value);

               

    dlgCell(0,2) dlgLabel(E.package.name);

               

    for (select_num = 0; select_num < MAX_TEXT; select_num++)

                

    {

                 

    if ( select_num == 8)

                  

    {

                   

    dlgCell(select_ele_num,0,select_ele_num,2)

                   dlgPushButton(""selects[select_num]) dlgAccept(select_num);

                  

    }

                 

    else

                  

    {

                   

    dlgCell(select_ele_num,0,select_ele_num,2)

                   

    dlgPushButton(selects[select_num]) dlgAccept(select_num);

                  

    }

                

    }

              

    }

            

    };

     

    The first works OK, the second NO, it returns always 8.

     

    Amelia.

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to Former Member

    ameliaamelia wrote:

    Again, two complete examples:

     

    >> ///////////////////////////////// 1- direct definition with constant

    >> //////////////////   |   |

    int select_dlg;

     

    >>   | select_dlg = dlgDialog("XXXX") |

    >>   | { |

    >>   | dlgGridLayout |

    >>   | { |

    >>   | dlgCell(0,0) dlgLabel(E.name); |

    >>   | dlgCell(0,1) dlgLabel(E.value); |

    >>   | dlgCell(0,2) dlgLabel(E.package.name); |

    >>   | dlgCell(1,0,1,2) dlgPushButton("Text1") dlgAccept(0); |

    >>   | dlgCell(2,0,2,2) dlgPushButton("Text2") dlgAccept(1); |

    >>   | dlgCell(3,0,3,2) dlgPushButton("Text3") dlgAccept(2); |

    >>   | dlgCell(4,0,4,2) dlgPushButton("Text4") dlgAccept(3); |

    >>   | dlgCell(5,0,5,2) dlgPushButton("Text5") dlgAccept(4); |

    >>   | dlgCell(6,0,6,2) dlgPushButton("Text6") dlgAccept(5); |

    >>   | dlgCell(6,0,6,2) dlgPushButton("Text7") dlgAccept(6); |

    >>   | dlgCell(6,0,6,2) dlgPushButton("Text8") dlgAccept(7); |

    >>   | dlgCell(7,0,7,2) dlgPushButton("+Text9") dlgAccept(8); |

    >>   | } |

    >>   | }; |

    >>   |   |

    ///////////////////////////////// 2- using a loop with variable

    /////////////////////// int MAX_TEXT = 9;

    string selects[] =

    {

    >>   | "Text1", |

    >>   | "Text2", |

    >>   | "Text3", |

    >>   | "Text4", |

    >>   | "Text5", |

    >>   | "Text6", |

    >>   | "Text7", |

    >>   | "Text8", |

    >>   | "Text9" |

    };

     

    int select_dlg;

    int select_num;

     

    >>   | select_dlg = dlgDialog("XXXX") |

    >>   | { |

    >>   | dlgGridLayout |

    >>   | { |

    >>   | dlgCell(0,0) dlgLabel(E.name); |

    >>   | dlgCell(0,1) dlgLabel(E.value); |

    >>   | dlgCell(0,2) dlgLabel(E.package.name); |

    >>   | for (select_num = 0; select_num < MAX_TEXT; select_num++) |

    >>   | { |

    >>   | if ( select_num == 8) |

    >>   | { |

    >>   | dlgCell(select_ele_num,0,select_ele_num,2)|

    >>   dlgPushButton(""selects[select_num]) dlgAccept(select_num);  | |

    >>   } | | else |

    >>   | { |

    >>   | dlgCell(select_ele_num,0,select_ele_num,2)|   |

    >>   dlgPushButton(selects[select_num]) dlgAccept(select_num);  | | } |

    >>   | } |

    >>   | } |

    >>   | }; |

     

    The first works OK, the second NO, it returns always 8.

     

    Amelia.

     

    You are correct (I get it always returning a 9)  but I can see that is not

    what you want.

    Each of your buttons is built with the statement containing

    dlgAccept(select_num); The variable isn't resolved as the button statement

    is stored but rather the statement is stored verbatum to run later as the

    variable name "select_num". So it always returns its current value no matter

    which button is clicked.

     

    Maybe someone has coded around this limitation  before and can offer a

    solution.

     

    Warren

     

     

     

    --

    Viewed / responded via the newsgroup at

    news.cadsoft.de

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • dukepro
    dukepro over 13 years ago in reply to Former Member

    Amelia,

     

    Your problem demonstrates that the argument is passed by reference, that

    is, a pointer to the integer value is what is actually passed.

     

    The argument to dlgAccept() is passed by reference, not by value.  ULP

    is somewhat object oriented in that an int is always a reference to an

    integer object, much like a Java Integer.

     

    In the first scenario (direct definition), each constant value is

    promoted to an integer object and is given a value that can not be

    changed, and a reference to that object is passed to dlgAccept().  Thus,

    any changes to the value of what's at the pointer, also changes the

    value that dlgAccept() uses as a return value.

     

    Contrast this to a procedural language, like C, where integers are

    passed by value.  i.e. a copy of the value is given to the called

    function, which can then manipulate the value without interfering with

    the value of the original integer.  Also, changes to the original

    integer do not affect the value that was passed to the called function.

     

    One work around would be to initialize an array of integers with each of

    the value return values, just like what you have done with the selects[]

    string array.  Then pass each of these as argument to dlgAccept().

     

    string selects[] =

    {

         "Text1",

         "Text2",

         "Text3",

         "Text4",

         "Text5",

         "Text6",

         "Text7",

         "Text8",

         "Text9"

    };

    int selectNums[] = { 1,2,3,4,5,6,7,8,9 };

    int select_num;

    ...

     

         for (select_num = 0; select_num < MAX_TEXT; select_num++)

         {

              ...

              dlgPushButton(selects[select_num]) dlgAccept(selectNums[select_num]);

         }

     

     

    Hope this helps,

        - Chuck

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to dukepro

    Chuck Huber wrote:

    Amelia,

     

    Your problem demonstrates that the argument is passed by reference,

    that is, a pointer to the integer value is what is actually passed.

     

    The argument to dlgAccept() is passed by reference, not by value.  ULP

    is somewhat object oriented in that an int is always a reference to an

    integer object, much like a Java Integer.

     

    In the first scenario (direct definition), each constant value is

    promoted to an integer object and is given a value that can not be

    changed, and a reference to that object is passed to dlgAccept().

    Thus, any changes to the value of what's at the pointer, also changes

    the value that dlgAccept() uses as a return value.

     

    Contrast this to a procedural language, like C, where integers are

    passed by value.  i.e. a copy of the value is given to the called

    function, which can then manipulate the value without interfering with

    the value of the original integer.  Also, changes to the original

    integer do not affect the value that was passed to the called

    function.

     

    One work around would be to initialize an array of integers with each

    of the value return values, just like what you have done with the

    selects[] string array.  Then pass each of these as argument to

    dlgAccept().

     

    string selects[] =

    {

    "Text1",

    "Text2",

    "Text3",

    "Text4",

    "Text5",

    "Text6",

    "Text7",

    "Text8",

    "Text9"

    };

    int selectNums[] = { 1,2,3,4,5,6,7,8,9 };

    int select_num;

    ...

     

    for (select_num = 0; select_num < MAX_TEXT; select_num++)

    {

    ...

    dlgPushButton(selects[select_num]) dlgAccept(selectNums[select_num]);

    }

     

    >

    Hope this helps,

        - Chuck

     

    Chuck's suggested work around does not solve the problem for the same

    reasons as Amelia's.

    The result is the same. (v4.16)(v5.12)

     

    The UL does not appear to resolve variables in the statement code of the

    dlgPushButton, and holds the variable in tact so the present value of

    "select_num" is used when the statement runs. As I see it you cannot

    determine which button has been clicked. I would like to see the technique

    that shows me I'm wrong.

     

     

    dlgListView or dlgLIstBox  is likely a better approach than a large number

    of buttons created in a loop.

     

    Would Alf or Walter please comment?

     

    Thanks

    Warren

     

    --

    Viewed / responded via the newsgroup at

    news.cadsoft.de

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ameliaamelia
    ameliaamelia over 13 years ago in reply to Former Member

    To Warren,

     

    You are right, see my last analisys on http://www.element14.com/community/message/52947#52947/l/url-dlgaccept

     

    Amelia

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube