6 Replies Latest reply on Nov 18, 2010 9:45 AM by philmodjunk

    How to select the 4th character over left to right

    rjlevesque

      Title

      How to select the 4th character over left to right

      Post

      I need to be able to read the 4th character in a field to match it against another.

      Basically

      ----------------------------------------------

      If 4th character from left to right is equal to <mastercharacterhere>

      do this

      else if blah blah blah

      do this

      halt script

      end if

        • 1. Re: How to select the 4th character over left to right
          philmodjunk

          If [ Middle ( TextField ; 4 ; 1 ) = "<mastercharacterhere>" ]

          • 2. Re: How to select the 4th character over left to right
            rjlevesque

            so it tells FM go 4 characters over and select just 1 character...awesome! Thanks Phil, you Da man!

            • 3. Re: How to select the 4th character over left to right
              rjlevesque

              Ok, so where am I being an idiot here please Phil?

              If [Middle ( Functions::Function Read ; 4 ; 1 ) = "-"]
                  Freeze Window
                  Enter Find Mode [Restore]
                  Go To Related Record [Show only related records; From table: "Tanks - Detailed View"(Tanks);New Window]
                  Enter Browse Mode
                  Halt Script
              Else
                  Go to Field [Functions::Function Read]
                  Set Field [Functions::Function Read; ""]
                  Halt Script
              End If

              -------------------------------------------------------------------------------------------------

              NOTE: Tanks::Tk_Location: [== Functions::Function Read] is the Find criteria

              -------------------------------------------------------------------------------------------------

              Do I need to store the contents of the field as a global first and then perform the find? It tells me it cannot find it then gets stuck in a loop and I have to use the 3 finger solute to stop it.

              • 4. Re: How to select the 4th character over left to right
                philmodjunk

                You can't refer to a field when setting up Enter Find Mode [Restore]

                Do this instead:

                Set variable [$Func ; Value: Functions::FunctionRead ]
                Enter Find Mode[]
                Set Field [ Tanks::Tk_Location ; "==" & $Func ]
                Perform Find []

                Two other things to be careful of here.

                1. You are referring to two different table occurrences, Functions and Tanks, which one your current layout is based on will have a major effect on what happens when you perform this find.
                2. Go To Related record should not be used while in Find Mode. Perhaps you left out a Find[] Step when you posted your script. You should also first test to see if there is any related record before using Go To Related Record. If there are no related records in the Tanks table, the script keeps you on the current layout and your script moves on to the next step and tries to execute it--which with some scripts results in a major catastrophe.
                • 5. Re: How to select the 4th character over left to right
                  rjlevesque

                  ok but is that correct for what i need it to do? I need it to read what is scanned into field Functions::FunctionRead and find that entry in Tanks::Tk_Location, then display that found record in a new window.

                  • 6. Re: How to select the 4th character over left to right
                    philmodjunk

                    In that case:

                    Set variable [$Func ; Value: Functions::FunctionRead ]
                    New window [//specify details on your new window here]
                    Go To Layout [Select layout based on Tanks unless you are already on such a layout]
                    Enter Find Mode[]
                    Set Field [ Tanks::Tk_Location ; "==" & $Func ]
                    Perform Find []

                    If FunctionRead is a global field, you can remove the first line and replace $Func in the set field expression with a reference to the gobal field.