11 Replies Latest reply on Mar 14, 2011 2:50 PM by julieFrith

    formatting numbers...

    julieFrith

      Title

      formatting numbers...

      Post

      i've already been helped with a number formatting script but i got my original question wrong so i hope you may all be able to help again. 

      I need to create a script that will generate a certain number of new records. However, the records need to be formatted as follows...

      If i need 5 new records - they will format as record number... 1,2 3, 4, 5

      If i need 15 new records - they will format as record number... 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11 etc

      If i need 115 new records - they will format as 01.... 011.... 115... 

      Any help would be appreciated, as always. 

      Thanks

      Jules

        • 1. Re: formatting numbers...
          Frinholp

          Could you explain why you would like to do this?

          If you create 5 so 5 new records have values 1, 2, 3, 4, 5, then create 5 more, these records would also have values 1, 2, 3, 4, 5? What do these numbers represent? 

          Lee

          • 2. Re: formatting numbers...
            philmodjunk

            Case ( $count < 10; numberfield ;
                      $count < 100 ; Right ( "0" & numberfield ; 2 ) ;
                      Right ( "00" & Numberfield ; 3 )
                     )

            Exactly how you implement that will depend on what you are trying to do here. A (possibly global) field may be subsituted for $count if that better serves your needs.

            There's also a function called SerialIncrement, you may want to investigate here.

            • 3. Re: formatting numbers...
              julieFrith

              Hi 

              Thanks for the replys.  i think what i'm saying is i need the script which generate the number of defined new records records and creates a field with a unique code based on the number of digits in the initial number request. 

              e.g Number of apartments = 18

              This would create 18 new records. 18 is 2 digits so every code it generates would be 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11 and so on to 18..

              eg Number of apts = 123

              This would create 123 new records. 123 is 3 digits in length, so every code the script generate would be 001, 002, 004 and so on, 012, 013, 014 and so on 122, 123

              The inportance is generating the correct number of '0's 

              Phil..I have the number of apts as a global field if this helps. 

              thanks

              Jules

              • 4. Re: formatting numbers...
                philmodjunk

                Use number of apts in place of $count in my example.

                • 5. Re: formatting numbers...
                  julieFrith

                  hi phil. 

                  sorry its gone over my head a bit now... How do i get this working within a script? to create the correct number of records and code?

                  thanks

                  jules

                  • 6. Re: formatting numbers...
                    philmodjunk

                    I only addressed the formatting only. The records generation would occur in a looping script that loops once for every such record. There's also a simpler expression that can be used for the leading zeroes.

                    Set Variable [$maxDigits ; Value: Length ( YourTable::Number of Apts ) ]
                    Set variable [$MaxValue ; Value : YourTable::Number of Apts ]
                    Loop
                       Exit Loop if [$Apt= $MaxValue ]
                       Set Variable [$Apt ; Value: $Apt + 1 ]
                       New Record/Request
                       Set Field [YourTale::AptNo ; Right ("0000" & $Apt ; $MaxDigits )]
                    End Loop

                    • 7. Re: formatting numbers...
                      julieFrith

                      sorry to be a pain phil, i can't get it to work, the script does nothing..hmm...

                      The only difference in my script is.. 

                      Set Variable [$MaxValue; Value:ValueCount (New_Estate_Entry::New_Estate_Number_of_Apts)]

                       

                      yours is: 

                      Set variable [$MaxValue ; Value : YourTable::Number of Apts ]

                       

                      I can't find 'value' as a function. ?

                       

                      Jules

                      • 8. Re: formatting numbers...
                        philmodjunk

                        Value is not a function. It's just part of the automatic formatting that appears in the script editor after you finish entering the expression to the right of the colon and click OK.

                        • 9. Re: formatting numbers...
                          julieFrith

                          Ok sorted script but still doesn't work.. i think this is a bit beyond me. here's my script...but it does nothing i'm afraid..

                          Set Variable [$MaxDigits; Value:Length (New_Estate_Entry::New_Estate_Number_of_Apts)]
                          Set Variable [$MaxValue; Value:New_Estate_Entry::New_Estate_Number_of_Apts]
                          Loop
                          Exit Loop If [$Apt = $MaxValue]
                          Set Variable [$Apt; Value:$Apt + 1]
                          New Record/Request
                          Set Field [Apartment_Details::Estate_Apt_Number; Right ("0000" &Apt; $MaxDigits)]
                          End Loop 

                          Appreciate any help. 

                          • 10. Re: formatting numbers...
                            philmodjunk

                            What layout are you on when you run this script. Are you on a layout that refers to New_Estate_Entry or a layout that refers to Apartment_details?

                            This should be run on a layout that refers to Apartment _Details in order to create new records in the correct table. Since this is likely a related table of records, you'll almost certainly need at least one more set field step to assign the needed primary key value from your estate table to your matching foreign key field in the details table. There was also a typo in the set field step though that may not be there in your actual script.

                            I'm guessing here that you should have this script:

                            Freeze Window
                            Set Variable [$MaxDigits; Value:Length (New_Estate_Entry::New_Estate_Number_of_Apts)]
                            Set Variable [$MaxValue; Value:New_Estate_Entry::New_Estate_Number_of_Apts]
                            Set Variable [$EstateID; Value:New_Estate_Entry::EstateID]
                            Go To Layout [Apartment_Details]
                            Loop
                              Exit Loop If [$Apt = $MaxValue]
                              Set Variable [$Apt; Value:$Apt + 1]
                              New Record/Request
                              Set Field [Apartment_Details::Estate_Apt_Number; Right ("0000" & $Apt; $MaxDigits)]
                              Set Field [Apartment_Details::EstateID ; $EstateID]
                            End Loop
                            Go To Layout [original layout] 

                            • 11. Re: formatting numbers...
                              julieFrith

                              Sussed it. Thanks so much, your a godsend. Wink