Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

placement of condition in count command 21 Oct 2021 16:25 #20044

  • kevclark64
  • kevclark64's Avatar
  • Topic Author


  • Posts: 108
  • In Foxpro either of the following is valid:

    COUNT FOR state="CA" TO statecount
    COUNT TO statecount FOR state="CA"

    The X# compiler currently only allows the second construction in which the variable is named before the condition. I haven't tested it, but I wonder whether this is a general issue that might affect commands similar to COUNT.

    Please Log in or Create an account to join the conversation.

    placement of condition in count command 21 Oct 2021 17:16 #20048

    • robert
    • robert's Avatar


  • Posts: 2475
  • Kevin,
    The X# compiler allows to freely change the order of optional clauses in user defined commands.
    The COUNT command is declared as
    #command COUNT TO <var>    ;
             [FOR <for>]       ;
             [WHILE <while>]   ;
             [NEXT <next>]     ;
             [RECORD <rec>]    ;
             [<rest:REST>]     ;
             [ALL]             ;
             ;
          => <var> := 0 ;
           ; DbEval( ;
                     {|| <var> := <var> + 1}, ;
                     <{for}>, <{while}>, <next>, <rec>, <.rest.> ;
                   )
    As you can see: the TO <var> is not optional (not between brackets) and therefore not optional.
    I will see if I can tweak the command to allow TO <var> to be at the end of the command.
    Making the TO <var> clause optional would technically work and allow to swap the TO and FOR clauses.
    But if TO is missing then it would need to generate a compiler error.

    Robert

    Edit:
    Maybe we can add a special notation to indicate that the "optional" clause is not really optional but can be moved around freely.
    Something like this:
    #command COUNT [^TO <var> ]   ;
             [FOR <for>]       ;
    etc
    where the ^ character would tell the preprocessor that the TO <var> clause has to be matched.
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    placement of condition in count command 22 Oct 2021 09:38 #20075

    • lumberjack
    • lumberjack's Avatar


  • Posts: 709
  • Robert,

    robert wrote: Kevin,
    The X# compiler allows to freely change the order of optional clauses in user defined commands.

    I created quickly a new count command and it seems according to the .ppo file it creates the correct output.
    #command COUNT ;
             [FOR <for>]       ;
             [WHILE <while>]   ;
             [NEXT <next>]     ;
             [RECORD <rec>]    ;
             [<rest:REST>]     ;
             [ALL]             ;
             TO <var>    ;  // Note where the TO <var> is positioned
          => <var> := 0 ;
           ; DbEval( ;
                     {|| <var> := <var> + 1}, ;
                     <{for}>, <{while}>, <next>, <rec>, <.rest.> ;
                   )
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    placement of condition in count command 22 Oct 2021 09:47 #20076

    • robert
    • robert's Avatar


  • Posts: 2475
  • Johan,
    Yes that works. And it matches both
    COUNT TO Var FOR SomeCondition
    and
    COUNT FOR SomeCondition TO Var

    Why did I not think of that myself?
    I will adjust the UDC in our header file
    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    placement of condition in count command 22 Oct 2021 09:48 #20077

    • robert
    • robert's Avatar


  • Posts: 2475
  • Robert,
    I created quickly a new count command and it seems according to the .ppo file it creates the correct output.


    I use the (new) UDC Tester for this. That works very well !

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    placement of condition in count command 22 Oct 2021 10:00 #20079

    • lumberjack
    • lumberjack's Avatar


  • Posts: 709
  • Robert,

    robert wrote: I use the (new) UDC Tester for this. That works very well !

    I have to apologize was not focusing on computer work the last couple of months due to my eyes, but I am feeling ready to start again.
    Have downloaded the new version and will next week install and see how the next article in the Data-driven series progress.
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Last edit: by lumberjack.
    • Page:
    • 1