Switch Commnand

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Switch Commnand

  • Creator
    Topic
  • #50549
    John Zalesak
    Participant

      For some reason this does not work for me.

      set fldSep [string index $msg 3]

      set subSep [string index $msg 4]

      switch -exact — $character {

       $fldSep –

       $subSep {to this stuff}

      }

      The variables are being set to the correct values, it just will not go in.

      If I hard code it, it does work

      switch -exact — $character

       | –

       ^ {do this stuff}

      }

      What am I doing wrong?  I am sure it is simple but I am stumped.

      Thanks!

    Viewing 3 reply threads
    • Author
      Replies
      • #66575
        Steve Carter
        Participant

          If you use variables in your switch statement, it needs to look like this:

          switch -exact — $variable

             $checkOne {

                 # Do something here

             }

             $checkTwo {

                 # Do something here

             }

             default {

             }

          Steve

        • #66576
          John Zalesak
          Participant

            Thanks I will give it a try.

          • #66577
            Tom Rioux
            Participant

              John,

              Try this:

              switch -exact — $character

              $fldSep –

              $subSep {to this stuff}

              When you are using variables in the body of a switch you can’t use braces around the body of the switch.  You will need to use the backslash to escape any newlines.

              Hope this works for you…

              Tom Rioux

            • #66578
              John Zalesak
              Participant

                The fixed it

                Thanks a bunch

            Viewing 3 reply threads
            • The forum ‘Cloverleaf’ is closed to new topics and replies.