Sage 100

 View Only
  • 1.  Script Syntax question

    Posted 10-21-2019 00:14
    Hi All,
       I am struggling to get the "test" portion of my script to work.  I need to set the value for variables based on the planned quantity.  Per everything I read on VBS, this should work but Sage does not like it. (pretty sure for one that it doesn't like elseif)   I am wondering how to setup nested if tests in scripts for Sage 100, as I have never seemed to be able to get them to work.    Thanks in advance! 

    If nPlanned <= 600 then
               n20560Qty = 500
    elseif nPlanned > 600 and nPlanned <= 900 then
              n20561Qty = 500
    elseif nPlanned > 900 and nPlanned <= 1100 then
              n20560Qty = 1000
    elseif nPlanned > 1101 and nPlanned <= 1300 then
             n20560Qty = 500 and n20561Qty = 800
    else nPlanned > 1301 and nPlanned <= 1500 then
                n20560Qty = 1500
    End if



    ------------------------------
    Robert Osborn
    Consultant
    ACI Consulting
    ------------------------------


  • 2.  RE: Script Syntax question
    Best Answer

    Posted 10-21-2019 08:37
    The only things I see are the extra AND in the last ELSEIF (should just be on its own line) and that you don't need a condition on an ELSE, so you can just change that to ELSEIF (or drop the conditions) and you should be good to go.

    If nPlanned <= 600 then
               n20560Qty = 500
    elseif nPlanned > 600 and nPlanned <= 900 then
              n20561Qty = 500
    elseif nPlanned > 900 and nPlanned <= 1100 then
              n20560Qty = 1000
    elseif nPlanned > 1101 and nPlanned <= 1300 then
             n20560Qty = 500
             n20561Qty = 800

    elseif nPlanned > 1301 and nPlanned <= 1500 then
                n20560Qty = 1500
    End if

    ------------------------------
    Steve Iwanowski, NextStep Technology Advisors, aka DSD Lancaster PA ¯\_(ツ)_/¯
    ------------------------------



  • 3.  RE: Script Syntax question

    Posted 10-21-2019 19:17
    Hi Steve, 

       It worked!  Thanks much.   Would be nice if there was something that explained the differences / limits to Sage Scripting vs 'regular' VB,  so I appreciate help from the trenches.

    ------------------------------
    Robert Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 4.  RE: Script Syntax question

    Posted 10-21-2019 11:30
    Robert, I agree with @Steve Iwanowski  about the extra AND statement.​​  Marcos

    ------------------------------
    Marcos DeLuna
    Deluna Consulting
    ------------------------------



  • 5.  RE: Script Syntax question

    Posted 10-21-2019 15:53

    Guys,

      This is a test to see what range the nPlanned is in to set the variable.   How do I do this without And statements?       

     

    And to be clear, I have tried all the different formats (elseif and else if,    else alone on the last line, etc) and none of them pass the sage syntax test.   This SHOULD work but if throws an error:

     

                    If nPlanned <= 600 then

                                    n20560Qty = 500

                    else if (nPlanned > 600 and nPlanned <= 900) then

                                    n20561Qty = 500

                    else if  (nPlanned > 900 and nPlanned <= 1100) then

                                    n20560Qty = 1000

                    else if  (nPlanned > 1101 and nPlanned <= 1300) then

                                    n20560Qty = 500 and n20561Qty = 800

                    else  (nPlanned > 1301 and nPlanned <= 1500) then

                                    n20560Qty = 1500

                    End if

    Thank you,

     

    Bob Osborn

    ACI Consulting

    p 714.282.0378 ext. 402    f 714.282.0235

     

    Bob@ACIconsulting.com

     

     ACISignature1                  

    This communication, including attachments, is confidential and may contain proprietary information intended only for the proposed recipient. Please notify the sender and delete this message if you believe that you have received this message in error or if you are not the proposed recipient. Unauthorized disclosure, copying, or distribution of the information is strictly prohibited.

     

     

     

     



    ------Original Message------

    Robert, I agree with @Steve Iwanowski  about the extra AND statement.​​  Marcos

    ------------------------------
    Marcos DeLuna
    Deluna Consulting
    ------------------------------


  • 6.  RE: Script Syntax question

    Posted 10-21-2019 16:03
    Else has no condition or "then"... you just go to the statement.

    ...
    else  n20560Qty = 1500
    end if



    Another option: select case true...
    https://www.codeproject.com/Questions/600175/Howplustoplususeplusrangeplusofplusvalueplusinplus

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 7.  RE: Script Syntax question

    Posted 10-21-2019 16:19
    What error are you getting if you just drop-in the code I wrote above?

    ------------------------------
    Steve Iwanowski, NextStep Technology Advisors, aka DSD Lancaster PA ¯\_(ツ)_/¯
    ------------------------------



  • 8.  RE: Script Syntax question

    Posted 10-21-2019 16:06
    I'm certainly not a programmer but here's a thought that may be helpful:  Use a case statement instead of an if than else statement.  Below is a possible structure - warning  - the syntax may not be correct... but it is something like this.

    Select Case nPlanned

    Case 1
    nPlanned <= 600
    then
    n20560Qty = 500

    Case 2
    nPlanned > 600 and nPlanned <= 900
    then
    n20561Qty = 500

    Case 3
    nPlanned > 900 and nPlanned <= 1100
    then
    n20560Qty = 1000

    Case 4
    nPlanned > 1101 and nPlanned <= 1300
    then
    n20560Qty = 500 and n20561Qty = 800

    Case Else
    nPlanned > 1301 and nPlanned <= 1500
    then
    n20560Qty = 1500

    End Select

    ------------------------------
    Doug Higgs
    Assistant Technical Support / Building Maintenance Specialist
    Midwest Commerce Solutions, Inc
    ------------------------------



  • 9.  RE: Script Syntax question

    Posted 10-21-2019 16:23
    Doug,
    VBScript's implementation of Select Case does not allow ranges, unless you use the technique I linked above.

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 10.  RE: Script Syntax question

    Posted 10-21-2019 16:35
    Good to know @Kevin Moyes  Thanks. ​

    ------------------------------
    Doug Higgs
    Assistant Technical Support / Building Maintenance Specialist
    Midwest Commerce Solutions, Inc
    ------------------------------