Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5113 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi all

I have used a custom function created by Fabrice Nordmann that holds all fields on a layout in global variables using the field name as the the variable name.

I have found this function to be extrememly useful so far, but have found a limitation - If a field contains a quotation mark ", the variable will not be created.

Here is the function:


/*

VariablesFromFields ( )

by Fabrice Nordmann

with thanks to Agnès Barouh, Ugo di Luca and Daniele Raybaudi



v2.1 : Sept 2007. Fixed a bug with carriage return

v2 : no more parameter is needed (was VariableFromFields ( start ))



Loads all current layout fields in named global variables



i.e. current layout has :

field "A" that contains "1",

field "B" that contains "2",

field "C" that contains "3"



Evaluating this function will result in 3 global variables :

$$A will contain "1"

$$B will contain "2"

$$C will contain "3"



Among other ways of evaluating this calculation, you can use :

- a Set Variable script step [ $temp ; VariablesFromFields ( ) ]

- an unstored calculation field on your layout and defined as = VariablesFromFields ( )

   In this case, you will need to refresh window to load variables.



This demo uses an unstored calculation : the field has to be named "VariablesFromFields, and must be put first on layout.

-----------------*/



Let([

_fields = FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ;

_end = ValueCount ( _fields ) ;

$$cfVFF_counter = Case ( IsEmpty ( $$cfVFF_counter ) ; 1 ; $$cfVFF_counter > _end ; "" ; $$cfVFF_counter + 1 ) ;

_fieldName = GetValue ( _fields ; $$cfVFF_counter ) ;

_value = Substitute ( GetField ( _fieldname ) ; ¶ ; "¶" ) ;

_textEval = "let ( $$" & _fieldname & " =" & Case ( IsEmpty ( _value ) ; """" ;  """ & _value & """ ) & "; "")"

];

Case (

$$cfVFF_counter <= _end ; If ( _fieldName ≠ "VariablesFromFields" ; Evaluate ( _textEval ) & VariablesFromFields ( )

)

))

My coding skills aren't fantastic, but I'm always willing to learn and try to solve the problem.

I'm assuming the problem lies within this segment of code?

_textEval = "let ( $$" & _fieldname & " =" & Case ( IsEmpty ( _value ) ; """" ; """ & _value & """ ) & "; "")"

];

Could anybody please guide me through this line?

Your help would be greatly appreciated

Lee

Posted

Hi

try to change this:

_value = Substitute ( GetField ( _fieldname ) ; ¶ ; "¶" )

to:

_value = Substitute ( GetField ( _fieldname ) ; [ """ ; """ ] ; [ ¶ ; "¶" ] )

  • 2 months later...
Posted

Hi Fabrice

I noticed that the function was failing recently and remembered I had switched on smart quotes in the file options.

Could I recommend that the following line:

_value = Substitute ( GetField ( _fieldname ) ; [ """ ; """ ] ; [ ¶ ; "¶" ] )

be updated to:

_value = Substitute ( GetField ( _fieldname ) ; [ """ ; """ ] ; [ ¶ ; "¶" ] ; [ Char (8220) ; "" & Char (8220) ] ; [ Char (8221) ; "" & Char (8221) ] ) ;

to cater for smart quotes.

Thanks

Lee

This topic is 5113 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.