In support of the 64 bit version of FRED Optimum, the previous version of the BASIC scripting language has been replaced with a newer version. This necessary change brings with it a much stricter and more modern version of BASIC without sacrificing any of the flexibility and power FRED users have come to rely on. Ultimately, the goal of the development staff has been to implement this change with as little impact on existing scripts as possible. However, for users with scripts from FRED v9.32 or earlier, the following information should be noted.
Updating scripts to the current syntax For scripts written in FRED v9.32 or earlier, there is a utility which will convert scripts with the new syntax requirements. With a script open in the editor, navigate to Menu > Script > Repair Old Style Script Syntax. Although the staff has done its best to consider all scenarios, we recommend backing up a copy of the original script in the event that the conversion fails or unexpected problems occur.
Please note the following known issues: •Global Script variable dimension statements must be removed manually, otherwise they are considered local variables •Dialog boxes must be manually re-sized due to differences in definition between the new and old versions •Option Explicit must be commented out, or Option Explicit Off must be used in order to allow dimensioning using x&, x$, x!, etc.
Changes in the new scripting implementation The following items detail some important differences between the new and old implementations of FRED's scripting language.
The new editor is much more modern than that used in previous versions of FRED. Some new options have been added to the Format tab of the Preferences menu (Menu > Tools > Preferences > Format) which allow some commonly used settings to be customized. Read more about this here.
Users may notice that the new editor environment is much "smarter" than the old environment. On the left hand side of the editor both line numbers and an outline of the current script are shown. The outline feature allows you to expand or collapse subroutines and functions by selecting either the "+" or "-" icons (this is also an option in the Preferences settings). Additionally, as the cursor position is moved through out the script the current procedure (subroutine or function) being edited is shown on the top right of the environment in the Proc: box. You can conveniently select subroutines and functions from the Proc: list to automatically move your cursor to that position.
When writing the script the editor also has completion capabilities. Specifically, when dimensioning a variable the auto-completion list is displayed for variable types. When typing FRED extensions the user must use the keystroke Ctrl + Space to bring up the auto-completion list. Typing while the list is displayed will automatically find the closest entry, which can then be selected by hitting Tab. The auto-completion utility allows rapid searching through the FRED library for correct syntax.
Scripts now require a Sub Main()...End Sub around the body of the script. The Repair Old Style Script Syntax utility places a Sub Main() into the script being repaired.
The new scripting version uses enhanced COM, through which FRED's capability to communicate with external programs is greatly improved. For an example of how to use the FRED type library, please see the Automation Fundamentals help topic.
When editing a script there will be two status bars in the main FRED window, one for FRED and a separate status bar for the scripting editor. The scripting editor status bar is shown immediately below the scripting editor window and will only display events related to scripting. Having this dedicated status bar removes the possibility that a FRED event will erase any messages related to the scripting that could be used for debugging. Display of this status bar can be set in the FRED Preferences on the Format tab.
Printing blank lines in script now only requires an empty Print statement, rather than a print statement followed by empty quotations.
Printing values to the output window By default, the argument of a Print statement will be printed as a string in the output window. If this value is later retrieved from the output window it will be recognized as a String type rather than a Double type. If you want to print a value to the output window as a Double you can embed the "#" symbol in front of the value being printed when the argument is passed to the Print statement. For example, suppose that we wanted to print the value 1.2345 to the output window as a Double. We would issue the Print statement in the following way: Print "#1.2345" Similarly, if the variable "A" has been dimensioned as a Double data type and contains the value 1.2345, we can print it as a value to the output window in the following way: Print "#" & A
Adding a semicolon at the end of a Print statement suppresses the carriage return. The next Print statement that is issued will be placed in the next column of the output window.
The following rules now apply to dimensioning of arrays: •If the array is explicitly dimensioned, you cannot re-dim the array. •If you do not explicitly dimension the array, you can re-dim the array at a later time. •If you do not explicitly dimension the array, you can re-dim the array in multiple dimensions using variables. •If you want to keep the data after a ReDim statement, the Preserve keyword must be used. You cannot change the dimensionality in this case.
The following operation is valid because the array "test" is not explicitly dimensioned: Dim test( ) As Double ReDim test( 4,5 ) ReDim test( 3 )
The following operation is not valid because the array "test" is explicitly dimensioned: Dim test( 4 ) As Double Dim test( 5, 4 ) As Double
The following operation is a valid use of the Preserve keyword: Dim test( ) As Double ReDim test( 1, 5 ) ReDim Preserve test( 1, 10 )
The following operation is not valid because the Preserve keyword has been used and the dimensionality is being changed: Dim test( ) As Double ReDim test( 1, 5 ) ReDim Preserve test( 2, 5 )
The following operation is a valid method of dimensioning an array with variables: Dim x As Long Dim y As Long
Dim test( ) As Long ReDim test( x, y )
Document related scripting commands When the script editor is active without an open FRED document, only FRED commands relating to the application will be available. Any FRED extensions that require a document will not be available.
Dimensioning global script variables Global script variables can no longer be dimensioned inside of the script using them, otherwise they are treated as local variables. In the new scripting version, the variables can be referenced exactly as they are defined in the global script variables dialog.
By default, the new scripting implementation uses Option Explicit to enforce adherence to proper syntax. In the script editor the Option Explicit line can be removed or replaced with Option Explicit Off. In a Sub Eval, such as used in the scripted surfaces, scatter, coatings, etc. dialogs, Option Explicit Off should be used.
Having Option Explicit means that statements using the syntax such as:
x& = FindName( "My Entity" )
where x& dimensions the variable x as a long will no longer be acceptable syntax.
Concatenating Print statement text Statements printed to the output window must now be joined using a ";" rather than a ",". For example the following statement is NOT allowed:
Print "My Test = " , value
This syntax must be changed to:
Print "My Test = " ; value
The Wait command in the new scripting language takes its argument in seconds rather than milliseconds.
Scripted surfaces, coatings, materials and scatter Scripted entities such as surfaces, coatings, materials and scatter are now evaluated within explicitly defined subroutines. For example, in previous versions of FRED the default scripted GRIN material was entered as:
N0=1.5 : A=-0.01 g_N = N0 + A*(g_x*g_x + g_y*g_y) g_dNdx = 2*A*g_x g_dNdy = 2*A*g_y g_dNdz = 0
However, the new scripting language requires this material to be defined in the following way:
Sub EvalGRIN( ByVal g_x#, ByVal g_y#, ByVal g_z#, ByVal g_w#, ByRef g_N#, ByRef g_Nimag#, ByRef g_dNdx#, ByRef g_dNdy#, ByRef g_dNdz# ) Const N0=1.5 Const A=-0.01 g_N = N0 + A*(g_x^2 + g_y^2) g_dNdx = 2*A*g_x g_dNdy = 2*A*g_y g_dNdz = 0 End Sub
This new definition style has implications particularly within embedded or standalone scripts where definition of a scripted entity requires a string argument. Users should modify their scripts to add the Sub Eval..End Sub strings to their scripted entity definitions.
Pre-compiled library files are no longer supported. The FRED extension commands CreateLib and GetEmbeddedScriptLib as well as the core object module methods CompileFile and CompileText will return FRED library objects. The FRED extension GetLib can no longer be used since scripts are no longer compiled into *.frl files. Additionally, please note that there is no way to recover scripts that have already been compiled into *.frl files.
|