Announcement

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

  • Checking if certain options are passed to a program

    Hi, I'm writing a program that allows quick generation of histograms with different popular bin widths, and a combined graph with all of them to compare which one better fits the data. The syntax for the program is
    Code:
    syntax varname(numeric) [if] [in] [fweight] , MEthod(string)[*]
    In the method() option the user specifies which bin width to use. The * wildcard is to allow for all other options you can pass to the histogram command. However, since the width or bin will be set by the selected method, I want to check if these options are passed to return an error. My question is how do I check if these options have been passed in the `options' macro.

    Thanks for any help,
    Last edited by Alfonso Sánchez-Peñalver; 01 May 2014, 20:29. Reason: Added tags
    Alfonso Sanchez-Penalver

  • #2
    Alfonso,

    ​I'm not sure I understand your question, but as I understand the syntax command documentration, any additional options provided are collected together and put into `options' as one big string. So, how about something like:

    Code:
    syntax...
    if (strpos("`options'","width") | strpos("`options'","bin")) {
      di "error"
    }
    Or is the problem that the width option could be abbreviated as w, wi, wid, or widt? I can't think of an elegant solution at the moment, but you could simply add more strpos functions for each of those possibilities (surrounded by spaces).

    Alternatively, you could make width and bin optional options and then throw errors if they are actually used:

    Code:
    syntax ... , MEthod(string) [Width  bin *]
    if ...
    Regards,
    ​Joe

    Comment


    • #3
      Ah Joe,

      the second option sounds better, because width can actually be abbreviated. I was using strpos() but I was concerned because width could be abbreviated to w, even if I looked for w( any number of options can end up in w and have a parenthesis after. So I think that the second method you suggest is more elegant.

      Thanks,
      Alfonso Sanchez-Penalver

      Comment


      • #4
        Ahh yes, those pesky parentheses....that last solution was an afterthought; glad I thought of it.

        Comment

        Working...
        X