6 Replies Latest reply on Mar 24, 2016 11:30 AM by beverly

    Advanced unique character generator

    amiranda

      Hi All

       

      I'm not a FMP expert by any stretch of the imagination. I think this request is simple but could be very wrong. Please let me know if this is confusing:

       

      The objective: Create a unique "style number" It will be created by adding  an established naming convention with an auto generated two character code. The style number must be exactly 4 characters.

       

      Table 1

      Department Information: This table contains a department description and a manually generated two character code.

      Example:    Field1: Fashion

                          Field 2:FM (unique, manually created)

       

      Table 2:

      Item Creation: This is where the end user will obtain the unique, incremental value. Due to limited number of possible combinations, the two trailing characters cannot be unique -however, the entire combination must be unique.

      Example:

                  Record 1

                    Field 1: FM - (can be a dropdown from table 1)

                    Field 2: 01 - (This should be auto generated)

                    Field 3:  FM01 Output/Assigned number


                    Record 2

                    Field 1: FM - (can be a dropdown from table 1)

                    Field 2: 02 - (This should be auto generated)

                    Field 3:  FM02 Output/Assigned number

       

                     Record 3:

                    Field 1: AL - (can be a dropdown from table 1)

                    Field 2: 01 - (This should be auto generated)

                    Field 3:  AL01 Output/Assigned number


      Output:, FM02, FM03, AL01, AL02, FM04, AL03, etc...

       

      Important, The solution must assign alpha numeric "Item codes" This gives us upwards of 1200 combinations per style number vs just 99.

       

      Any input would be greatly appreciated.

        • 1. Re: Advanced unique character generator
          dtcgnet

           

           

          Important, The solution must assign alpha numeric "Item codes" This gives us upwards of 1200 combinations per style number vs just 99.

           

          Do you mean that the auto-generated two digit code would number from 01 to 99 and then from AA to ZZ or something like that?

           

          So you might have FMAZ, for instance?

          • 2. Re: Advanced unique character generator
            beverly

            a-z and 0-9 would generate 1,296 (36x36), two characters only

            add A-Z and you take it to 3,444 (62x62) two character combinations

             

            create a loop script (outer and inner loop) and see how many records might be created out of a set of alpha-numerics.

            beverly

            • 3. Re: Advanced unique character generator
              amiranda

              For the purpose of this solution, "a" and "A" are considered the same.

               

              Character types should combine ie 1A, A2, A1, 2A etc.

               

              The output must be dependent on the department code.

               

              If this is too difficult, I may be able to designate a third character to the auto-generated field (table 2 ,field 2). At that point, every item will have a unique three character sequence irrespective of the department code. That will provide upwards of 40k unique combinations.

              • 4. Re: Advanced unique character generator
                dtcgnet

                Going to the "end game"...There will come a time when you may want to sort by StyleNumber. That will happen in this order:

                FM00

                FM01

                ...

                FM99

                FM0A

                FM0B

                ...

                FM1A

                FM1B

                ...

                FMA0

                FMA1

                 

                And so on. If you think about it...the "code" that is "next" in line will be a bit difficult to determine. Let's say you create an item which is assigned "A9". Telling FileMaker to pick the next code in line will be a bit difficult. It would probably be "AA".

                 

                I think I'd make a table with every combination (use inner and outer loops as Beverly has suggested), and I'd assign a straight numeric value to each code. Then you could have your system determine the last code which was used, select the number associated with that code, then select the code associated with the number which is one higher than that.

                 

                A9 = 103, for instance.

                AA = 104, for instance.

                A9 was used. System determines that's code 103. System decides 104 is next, and assigns AA.

                 

                OR...Use something like FM0001, FM0002, etc. That'll be quite a bit easier to manage, I'd think.

                • 6. Re: Advanced unique character generator
                  beverly

                  I just wrote this script to generate with a-z & 0-9 taking two characters. revise to fit your needs. there may be functions that let you auto-enter. YMMV

                   

                  # create a string to use

                  Set Variable [ $digits; Value:"0123456789" ]

                  Set Variable [ $counter; Value:97 // start with char "a" ]

                  Loop

                  Set Variable [ $alpha; Value:$alpha & Char ($counter) ]

                  Exit Loop If [ $counter=97+25 // a-z ]

                  Set Variable [ $counter; Value:$counter + 1 ]

                  End Loop

                  Set Variable [ $alphaNums; Value:$alpha & $digits ]

                   

                  # actual loop

                  Set Variable [ $counter2; Value:1 ] Loop

                  Set Variable [ $firstChar; Value:Middle ( $alphaNums; $counter2; 1 ) ]

                  Set Variable [ $counter3; Value:1 ]

                  Loop

                  Set Variable [ $myCode; Value:$firstChar & Middle ( $alphaNums; $counter3; 1 ) ]

                  New Record/Request

                  Set Field [ myTable::myCode; $myCode ]

                  Exit Loop If [ $counter3 = Length ( $alphaNums ) ]

                  Set Variable [ $counter3; Value:$counter3 + 1 ]

                  End Loop

                  Exit Loop If [ $counter2 = Length ( $alphaNums ) ]

                  Set Variable [ $counter2; Value:$counter2 + 1 ]

                  End Loop

                   

                  # produce records with these values: aa-a9, ba-b9, etc.

                  # could be set to variable(s) rather than a field

                  Just to show you what I meant by loops

                  beverly