1 2 Previous Next 15 Replies Latest reply on Aug 21, 2012 4:40 PM by philmodjunk

    Two conditions in a case statement?

    Kirk_1

      Title

      Two conditions in a case statement?

      Post

      Im searching a data base. When i do a search, I need the result i put into the Froniter_Mars::CF_02 field to be one of the following l5c, 5c, 1m, 2m, 5m, or 10m depending on the $weight.

      The way i have it written, the result i get is  a 0 in the CF_02 field.

      $Weight is 1700, the result i want to put into CF_2 is 1M.

      What am i doing wrong? Is it having two conditions in the case?

      If it is how can i write it to get the l5c, or the 5c or the 1m...?

       

      Let ( w =$weight ;

      Case ( w < 500 ; Fontier_Mars::CF_02 = "L5C" ;
                 w < 1000 ;  Fontier_Mars::CF_02 = "5C" ;
                 w < 2000 ; Fontier_Mars::CF_02 = "1M" ;
                 w < 5000 ; Fontier_Mars::CF_02 = "2M" ;
                 w < 10000 ; Fontier_Mars::CF_02 = "5M"  ;
                 w < 20000 ; Fontier_Mars::CF_02 = "10M" ;
      )
      )

        • 1. Re: Two conditions in a case statement?
          philmodjunk

          Let ( w =$weight ;

          Case ( w < 500 ;  "L5C" ;
                     w < 1000 ;  "5C" ;
                     w < 2000 ; "1M" ;
                     w < 5000 ; "2M" ;
                     w < 10000 ; "5M"  ;
                     w < 20000 ; "10M" ;
          )
          )

          • 2. Re: Two conditions in a case statement?

            It's best (IMHO) to use greater than and start with the largest value.

            > 20000...
            > 10000 ....
            > 5000...
            > 2000....
            > 1000...

            Next forget the let and use

            Case(

            $_weight > nbr; "stuff" ;

            )

            You don't say where you get $weight from and that might be the problem.

            $weight = get(scriptparameter)
            $weight = filelname
            ?

            That could be the problem also if $weight isn't getting a value.

            You can insert a dialog with $weight in the value field to see what it is. Let it display before the case step if this is a script. 

             

             

            • 3. Re: Two conditions in a case statement?
              Kirk_1

              Ok so a set value then a set field.

              I was trying to do it in one...

              Thank you

              • 4. Re: Two conditions in a case statement?
                philmodjunk

                You might be able to do it in one, but you'd need to explain where the value for your weight comes from.

                • 5. Re: Two conditions in a case statement?
                  Kirk_1

                  Using my data viewer... the $weight is 1700.

                  my set value and set field states work, but the calculation does not.

                  Let ( w =$weight ;

                  Case ( w < 500 ;  "L5C" ;
                             w < 1000 ;  "5C" ;
                             w < 2000 ; "1M" ;
                             w < 5000 ; "2M" ;
                             w < 10000 ; "5M"  ;
                             w < 20000 ; "10M" ;
                  )
                  )

                  It returns the result of l5c, the first one.

                  I succesfully use a variation of this earlier in the script.

                  If I revers the script it still comes up with the first 10M...

                  • 6. Re: Two conditions in a case statement?
                    philmodjunk

                    Sounds like $weight is evaluating as text instead of a number ("1700" is less than "500"  because the character "1" is less than "5"

                    Try using:

                    let ( w = getasnumber ( $weight ) ;

                    • 7. Re: Two conditions in a case statement?
                      Kirk_1

                      Its still pulling the 1st.

                      Ive used it as a varable through out the script, so there isn't a field in this file to change from a text to a number field.

                      It successfuly pulls it in from a paramater script below.

                      Let ( w = GetAsNumber ($weight) ;

                      Case (
                                 W < 20000; "10M";
                                 W < 10000; "5M";
                                 W < 5000 ; "2M";
                                 W < 2000 ; "1M";
                                 W < 1000 ; "5C";
                                 W < 500 ; "L5C";
                       
                            //    w < 500 ;  "L5C" ;
                             //    w < 1000 ;  "5C" ;
                              //   w < 2000 ; "1M" ;
                               //  w < 5000 ; "2M" ;
                              //   w < 10000 ; "5M"  ;
                              //   w < 20000 ; "10M" ;
                      )
                      )

                       

                      =============================================

                       

                       Let ( [
                                      $params = Get ( ScriptParameter ) ;
                                      $ozip = GetValue ( $params ; 1 ) ;
                                      $dzip = GetValue ( $params ; 2 ) ;
                                      $fak1 = GetValue ( $params ; 3 ) ;
                                      $weight = GetValue ( $params ; 4 );
                                      $shipstate = GetValue ( $params ; 5 ) ;
                                      $constate = GetValue ( $params ; 6)
                      ] ;
                          ""
                      )

                      • 8. Re: Two conditions in a case statement?
                        philmodjunk

                        I use a similar method, but with explicit set variable steps to pull paramter values all the time. It frequently pulls numeric data from the parameter list as text so I do think you need to put in a getasnumber step there somewhere. Either where I suggested it or as part of the expression that extracts it from the parameter list in the first place.

                        Note that 1700 is less than 20000 so you fixed the data type issue and then broke it again by going back to listing your values in descending order instead of ascending.

                        use this:

                        Let ( w = GetAsNumber ($weight) ;

                        Case (
                         
                                  w < 500 ;  "L5C" ;
                                   w < 1000 ;  "5C" ;
                                   w < 2000 ; "1M" ;
                                   w < 5000 ; "2M" ;
                                   w < 10000 ; "5M"  ;
                                   w < 20000 ; "10M" ;
                        )
                        )

                        • 9. Re: Two conditions in a case statement?
                          Kirk_1

                          Yep

                          That was silly i should have looked at first... it will always hit the on the higher numbers...

                          • 10. Re: Two conditions in a case statement?
                            Kirk_1

                            One more issue with the params script. 

                            On my data viewer everything shows up... i can see $shipstate and $constate, but

                            when i move it to another file i don't see the $shipstate or the $ constate.

                             

                            $ozip & "¶" &
                            $dzip & "¶"  &
                            $weight & "¶" &
                            $FAK1 & "¶" &
                            $shipstate & "¶" &
                            $constate & "¶"

                            ==========================================

                             Let ( [
                                            $params = Get ( ScriptParameter ) ;
                                            $ozip = GetValue ( $params ; 1 ) ;
                                            $dzip = GetValue ( $params ; 2 ) ;
                                            $weight = GetValue ( $params ; 3 );               
                                            $fak1 = GetValue ( $params ; 4 ) ;
                                            $shipstate = GetValue ( $params ; 5 ) ;
                                            $constate = GetValue ( $params ; 6)
                            ] ;
                                ""
                            )

                            • 11. Re: Two conditions in a case statement?
                              philmodjunk

                              variables (no dollar sign) only exist within the let function that created it.

                              $variables only exist as long as the script continues to execute and only within the context of that script.

                              $$Variables (called global variables) exist throughout a given file, but only that file and only for as long as the file is open.

                              If you want to pass this data to another file, you'll need to use other methods than variables.

                              A script parameter is the simplest.

                              You can also put the value in a field--can be a global field. Either use an external data source reference to a field from the other file or go to the other file and create an external data source reference to the table from the first file where you put your values from these variables.

                              • 12. Re: Two conditions in a case statement?
                                Kirk_1

                                I used a Paramater:

                                Set Variable [$infotoquote; Value:

                                $ozip & "¶" &
                                $dzip & "¶"  &
                                $weight & "¶" &
                                $FAK1 & "¶" &
                                $shipstate & "¶" &
                                $constate & "¶"

                                ================================ >>> move to 2nd file via script... the $ozip, $dzip, $weight, $fak1 move over and i use them successfuly. Im not catching the $shipstate or the $constate for some reason.

                                I can see the $shipstate or the $constate in the 1st script with all of the others, i lose the $shipstate or the $constate for some reason...

                                set Varable [infotoguote; Value:

                                Let ( [
                                                $params = Get ( ScriptParameter ) ;
                                                $ozip = GetValue ( $params ; 1 ) ;
                                                $dzip = GetValue ( $params ; 2 ) ;
                                                $weight = GetValue ( $params ; 3 );               
                                                $fak1 = GetValue ( $params ; 4 ) ;
                                                $shipstate = GetValue ( $params ; 5 ) ;
                                                $constate = GetValue ( $params ; 6)
                                ] ;
                                    ""
                                )

                                • 13. Re: Two conditions in a case statement?
                                  philmodjunk

                                  While I'd use this syntax:

                                  List ( $ozip ; $dzip ; $weight ; $FAK1 ; $shipstate ; $constate )

                                  (unless there is a chance that one of the variables might be empty), what you have should work.

                                  Do I remember correctly that you have advanced? if so, use the script debugger with data viewer to check the values of the variables to see if you can spot anything that is clearing the values of these two variables. If not, use a show custom dialog to put all three variables, infotoquote (missing a dollar sign?), $Shipstate and $Constate in the message box so you can inspect the values of these variables when the script executes. You can put the same step in different spots in your script to spot check their values.

                                  And remember that if a different script is assigning values to $Shipstate and $Constate, those values disappear once the script terminates. If that's the case, change them to $$Shipstate and $$Constate each place where you use them in your scripts.

                                  • 14. Re: Two conditions in a case statement?
                                    Kirk_1

                                    So use the list to retrieve the varables from the 1st?

                                     

                                    I have 11 advanced,

                                    I use the viewer... ill try the custom dialog.

                                    Im very careful that i don't mix them  or use them for other things and loose the values.

                                     

                                    1 2 Previous Next