KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Creating new object attributes from form variable will default as string
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: May 7, 2020

When adding new attributes to an object on a form, note that variables will default the data as a string value. Take the example below where the user enters the number "5" into the form variable Form.obj.var1. The data stored in Form.obj.var1 is a string value of "5" rather than the numeric value 5.



If a specific data type is required for an object attribute, always be sure to initialize the attribute during the form's On Load as this alternative will retain its data type.

Case of
   : (Form event code=On Load)
   Form.obj:=New object
   Form.obj.var1:=0
  
End case


Now when the user enters any numeric value, the attribute will stay numeric while still rejecting any alpha characters.