14 Replies Latest reply on Nov 26, 2014 11:06 AM by briancrockett

    Need custom text field

    UnrealIsm

      Title

      Need custom text field

      Post

       

       

      I am a IT Admin, and I am making a form so that we can track computer network information in our network for documentation. I need to create a format for two fields for consistency. Basically I need to make a "MAC Address" field and a "IP Address" field. I want it pre formatted so that all I got to do is type the info and it puts the format automatically like a phone number. So the text field would format like below.  Up address is numbers only and Mac address can contain letters and numbers.

      MAC address: 00:00:00:00:00:00

      IP Address: 192.168.100.100

      Thanks in advance

        • 1. Re: Need custom text field
          philmodjunk

          The Following auto-enter calculation should work:

          Let ( fld = Filter ( self ; 9876543210 );
                  case ( Length (fld) ≠ 12 ; self ; // input error, leave data unmodified
                            Left ( fld ; 2 ) & ":" & Middle ( fld ; 3 ; 2 ) & ":" & Middle ( fld ; 5 ; 2 ) & ":" & Middle ( fld ; 7 ) ; & ":" & Middle ( fld ; 9 ; 2 ) &
                                    ":" & Middle ( fld ; 11 ; 2 )
                           ) // case
                 ) // Let

          Clear the "do not replace existing value" check box

          The IP Address field would use a similar calculation but with a . separator and groups of 3 characters instead of 2.

          • 2. Re: Need custom text field
            SteveMartino

            Here's what I cobbled together, I'm sure theres a better way:

            Go into manage database, click on Mac Address field, Auto Enter tab, check Calculated value, and enter this calc.  After you are done, uncheck "Do not replace existing value of field (if any):

            Let (

            @Numbers = TextFormatRemove (Filter( Customers::zzzmac address ; "0123456789" )) ;

            Case(
            Length(@Numbers) = 12 ;

            Left(@Numbers ; 2) & ":" &
            Middle (@Numbers; 3 ; 2) & ":" &
            Middle (@Numbers; 5 ; 2) & ":" &
            Middle (@Numbers; 7 ; 2) & ":" &
            Middle (@Numbers; 9 ; 2) & ":" &
            Right ( @Numbers; 2 ) ;

            TextColor (Customers::zzzmac address ; RGB (255 ; 0 ; 0 ) )
            )
            )

            This will highlight the field in red if there isn't 12 digits.  But to give you instant feedback, and leave you in the field, I added this OnObjectExit script trigger:  Edit,small typo in script message, should read "...12 digits"  Not 10

             

             

            • 3. Re: Need custom text field
              briancrockett

              I'd be tempted to make the IP Number 4 different fields. One for each octet. Then a fifth calculation field to combine them. Unlike the Mac Address where each segment is exactly 2 characters, an IP can be 1 to 3. Therefore a simple calculation like the ones submitted by Phil & Steve wouldn't work.

              The Calc field would simply be:

              ip1 & "." & ip2 & "." & ip3  & "." & ip4

              ip1 to ip4 would be the added text fields.

              • 4. Re: Need custom text field
                UnrealIsm

                Brian,

                 

                Your kind of right, but not sure how to input that. I am new to Filemaker. I understand the code just enough to be dangerous. lol. Anyway, your right. Here is the problem with the IP situation. The IP is always going to be 4 octet groups. but I also need to find a way to fill in a octet is it is a single digit with zeros behind it. For example...

                I would type 1921681200 and it would need to look like 192.168.001.200.  Or...  I would type 19216810200 and it would look like 192.168.010.200. etc.

                I fiddled with Steves code, and I got this. It works, but need that leading zero if possible like above. I couldn't get Phils code to work, said too many parameters. 
                 

                Let (

                @Numbers = TextFormatRemove (Filter( Untitled::mac ; "0123456789" )) ;

                Case(
                Length(@Numbers) = 12 ;

                Left(@Numbers; 3) & "." &
                Middle (@Numbers; 4 ; 3) & "." &
                Middle (@Numbers; 7 ; 3) & "." &
                Right ( @Numbers; 3 ) ;

                TextColor (Untitled::mac ; RGB (255 ; 0 ; 0 ) )
                )
                )

                 

                • 5. Re: Need custom text field
                  SteveMartino

                  Phil's code works, but has a slight typo, on his 3rd "Middle" call out.

                  Make the field a text field, not a number field for your zero issue.

                  • 6. Re: Need custom text field
                    UnrealIsm

                    ah, I caught it and got phils to work. I will look at the IP address thing again. Can you explain the syntax briefly I understand it a little, but I am confused on how it works...

                    For example..

                    Left
                    Middle
                    Middle
                    Right

                    what is that?

                    And and towards the end of the syntax where is reads..
                    Left(@Numbers; 4 ; 3)  

                    what is the 4 stand for and the 3? I think the 3 is how many characters, but not getting the 4's purpose.

                     

                     

                    • 7. Re: Need custom text field
                      SteveMartino

                      I'll try...lol  There is no "Left(@Numbers; 4 ; 3)".  

                      Let (

                      @Numbers = TextFormatRemove (Filter( Untitled::mac ; "0123456789" )) ;

                      Case( Length(@Numbers) = 12 ;                                  Case function, if the length of the variable (@ numbers) = 12, do everything that follows the ; to the next semi-colon.  If the length does not equal 12, do what is after the 2nd semi-colon
                      Length(@Numbers) = 12 ;

                      Left(@Numbers; 3) & "." &   Left function, takes the variable string (@Numbers) use the first 3 numbers and add a . The "&" concatenates everything together
                      Middle (@Numbers; 4 ; 3) & "." & Middle function, take the variable string (@Numbers), start at the 4th character, use the next 3 characters and add a .
                      Middle (@Numbers; 7 ; 3) & "." & Middle function, take the variable string (@Numbers), start at the 7th character, use the next 3 characters and add a .
                      Right ( @Numbers; 3 ) ; Right function, take the last 3 characters of the string.

                      TextColor (Untitled::mac ; RGB (255 ; 0 ; 0 ) )  If Length does not equal 12, highlight text in red
                      )
                      )

                      • 8. Re: Need custom text field
                        briancrockett

                        I wouldn't count on users putting in leading zeros. I'd create 5 fields.  ip1 to ip4 just plain text fields. The fifth field a calculation field like I had in my previous post. Make the layout like the picture I included here. In layout mode under the layout menu there's a menu item called "Set Tab Order". Here you can set the fields so that your user can tab between them.

                        • 9. Re: Need custom text field
                          UnrealIsm

                          oh ok that makes sense. I got it. I kind of noticed it was doing that when I changed the numbers, but wasn't catching that first column's actions for some reason. But that is more clear now. =)

                          I need to wrap up that MAC address calculation, it works as needed, but I need it to contain letters as well as numbers. It has the ranges as below.

                          ABCDEF and 0123456789

                          Im using Phil's code if that helps.

                           

                           

                          • 10. Re: Need custom text field
                            briancrockett

                            Quick Tip:

                            I see most people use @ to designate a variable in their LET() statements. I use _ instead.

                            ex. @Numbers to _Numbers. 

                            Why? If you double click _Numbers the whole word selects including the underscore. If you use @ and double-click it won't select the @. So when you're copy and pasting you always have to waste time retyping the @.  It speeds up editing your formulas if you can double-click to select and cmd-c, cmd-v to copy & paste.

                            • 11. Re: Need custom text field
                              briancrockett

                              I need to wrap up that MAC address calculation, it works as needed, but I need it to contain letters as well as numbers. It has the ranges as below. ABCDEF and 0123456789

                              Use "ABCDEFabcdef0123456789" in the Filter() statement. You should also convert it to upper case at the same time.

                              UPPER(Filter ( self ; ABCDEFabcdef0123456789 ))

                              • 12. Re: Need custom text field
                                UnrealIsm

                                Brian,

                                I liked how you used the idea using separate text fields for the IP Address, and I think that might also work for the MAC addresses, however since I am a newbie at this my question is this... when I do set separate text fields, and I go into the table view, they are broken up into separate columns. Is there a way to set it so that I can take the 4 text files and make it show up as one column ? The reason I thought doing it in one text field is that way I can sort it easier.

                                • 13. Re: Need custom text field
                                  briancrockett

                                  The Fifth field ,which is a calculation, could be your single column as it will have all the data from the other 4. Or you could hide the fifth field and not display it to your users. Then all they would see is the 4 entry fields. 

                                  Sorting should actually be easier using the 4 fields as the presence or absence of leading zeros would throw out your sort when using a single field.

                                  • 14. Re: Need custom text field
                                    briancrockett

                                    I'm not sure why you would want to use table view anyway. List view gives you more control or how the layout looks. I only use table view for doing maintenance stuff I don't want users to see. Users aways get form view or list view.