
Here's the revised text for the example of a standard library:
An Example of a Standard Library
Many developers create a standard library for functions they use in every development project. This library can be initialized in the startup script where the binary code loads from a text field in a preference table or a similar location. For this purpose, you can create fields named ACFPack1, ACFPack2, ACFPack3, and ACFPack4. You can easily add more fields if you need more than four packages.
Here's an example calculation you can use in a "Set Variable" script step to load these packages:
Let( [
v = If (not IsEmpty ( Preferences::ACF_Pack1) ; ACF_Install_base64Text( Preferences::ACF_Pack1 ); "") ;
v = v & If (not IsEmpty ( Preferences::ACF_Pack2) ; ACF_Install_base64Text( Preferences::ACF_Pack2 ); "") ;
v = v & If (not IsEmpty ( Preferences::ACF_Pack3) ; ACF_Install_base64Text( Preferences::ACF_Pack3 ); "") ;
v = v & If (not IsEmpty ( Preferences::ACF_Pack4) ; ACF_Install_base64Text( Preferences::ACF_Pack4 ); "")
];
v
)
This calculation checks if there's content in each of the ACFPack fields and uses the ACFInstall_base64Text function to load the packages. You can add your code to one of the empty slots in these fields. Once you're finished, you can move your code to another package that contains the complete collection of functions.
Example:
This example demonstrates how you can use this approach to create a reusable library of functions that you can easily incorporate into your FileMaker solutions. It simplifies the process of managing and sharing common functionality across multiple projects.
package bootstrap "Functions to facilitate load and save source and binary files";
// Load some content from a file.
function LoadFile (string filename)
FunctionID 200;
string content;
int x;
x = open (filename, "r");
content = read (x);
close ( x ) ;
return content;
end
// Save some content on a file.
function SaveFile (string filename, string content )
FunctionID 201;
int x;
x = open (filename, "w");
write (x, content);
close ( x );
return 1;
end
// Select a file and return its content.
function SelectFile (string startPath, string Prompt)
FunctionID 202;
string cc = "";
string filename = select_file (Prompt, startPath);
if (filename != "") then
cc = LoadFile(filename);
end if
// Make also the filename available from FileMaker after the content is read.
$$FileName = filename;
return cc;
end
// Select a folder on the file system
function SelectFolder (string Prompt)
FunctionID 203;
string cc = "";
string folder = select_directory(Prompt);
return folder;
end
// Ask for a FileName to save to.
function SelectSaveAsFile (string prompt, string defname, string defdir)
FunctionID 204;
string filename = save_file_dialogue (prompt, defname, defdir) ;
return filename;
end
/*
Function to make 000 grouping with space, and decimal "comma" that is used in Norway.
*/
function BelFormat ( float bel )
bool negative;
if (bel < 0.0) then
negative = true;
bel = -bel;
end if
long reminder, f;
int ore;
string result = "";
reminder = bel;
ore = round ( (bel - reminder ) *100, 0);
// print "\n:" + reminder;
while ( reminder > long(0) )
// print "\n" + reminder;
f = mod ( reminder, 1000);
reminder = reminder / 1000;
if (reminder > long(0)) then
result = format ( " %03ld", f) + result;
else
result = string ( f ) + result;
end if
end while
if (negative) then
result = "-" + result;
end if
print "Time Used: " + uSec();
return format ( "%s,%02d", result, ore);
end
The last function "BelFormat" used to format number with space as 1000 separator and comma. Another variant of this would be to use a reg-ex function instead - dramatically reducing the complexity of the function.
This regex was found on: regexr.com
Like this:
function BelFormat ( float bel )
functionID 230;
string sbel = substitute ( format ( "%.2f", bel ), ".", "," ) ;
return regex_replace ( "\d{1,3}(?=(\d{3})+(?!\d))", sbel, "$& ") ;
end
Using this function, the following numbers get translated:
Input to the function | Result |
---|---|
1234 | 1 234,00 |
10469236 | 10 469 236,00 |
400,49 | 400,49 |
4000,228 | 4 000,23 |
40000,228 | 40 000,23 |
4369825,66 | 4 369 825,66 |
-200000 | -200 000,00 |
123456789 | 123 456 789,00 |