123 LotusScript Tips/FAQ's
|
|
1. How to use a range as argument in a custom @function ? The lack of documentation on this has caused a lot of head scratching. For example I want to create a custom @function to count the blank cells in a range: @countblank(A:A1..A:D300) has a corresponding function definition : Function COUNTBLANK(Rg) 123 sheet cells basically contain only two types of contents : STRING and DOUBLE. 123 custom @ functions are meant to accept cell contents and range arguments and they do this via the Variant type. Functions defined in 123 LotusScript can be used as custom @ functions only if the arguments are untyped or typed as Variants. Our example @countblank() is meant to count the total cells in a range would be defined as follows: Function COUNTBLANK(Rg) 'Allowed Rg treated as Variant Function COUNTBLANK(Rg As Range) 'Not Allowed in custom @ function must be untyped or variant. Function COUNTBLANK(Rg As Variant) 'Allowed but same as COUNTBLANK(Rg) custom @ function arguments are assumed to be a Variant. Variants can contain a large number of different argument types e.g. String, Integer, Long, Double and Range etc and the LotusScript function Typename() can be used to read the type of variable held by the variant. e.g. tname$ = Typename(Rg) would return "DOUBLE", "STRING", "LONG", "RANGE" if input as part of a custom @ function.
Instead do not specify any input argument types and test the arguments with
Typename(A) as in the sample below: |
|
| 2. Allowed property/method usage in custom @ functions ? Newcomers to custom @ function design using LotusScript will have noticed the
error dialog that warns : However, this is annoying when class methods look like they should be OK only to be rejected. For example the Cell method in the code below: Function MYATFUNCTION(Rg) This code sequence is not allowed because Cell() is a method you must use the Cells property instead : Function MYATFUNCTION(Rg) See Item 6 how to index a cell in a range using the above technique. As a general rule programmers of custom @ functions can only use 'Properties' of a 123 object and then only 'Get' not 'Set'. |
|
| 3. Calling DLLs from 123 with LotusScript. The 'Declare' statement in LotusScript facilitates the calling of external functions within DLLs. Using 'Declare' you can access the windows SDK performing functions not available within LotusScript itself e.g.:
You can also access your own compiled 32 bit DLLs using external windows language compilers e.g. Microsoft Visual C, Borland C++, Delphi etc. See Item 5. How do I construct a DLL with exported functions for 123? Below is a copy of a Lotus LotusScript 123 FAQ article :http://www.lotus.com/ QuoteHow do I call DLL functions?When you create LotusScript applications for 1-2-3, you are not limited to calling LotusScript procedures. Your LotusScript applications can call any procedures that are compiled in a dynamic-link library (DLL). To call procedures in a DLL, you need to know the following:
Note The following example calls a Win32 API function named sndPlaySound that is stored in the DLL file C:\WINDOWS\SYSTEM\WINMM.DLL.This function plays a Windows .WAV file. To use this function in a LotusScript application, first declare the function and then call it from a script. Enter the following statements in (Declarations) for (Globals) if you want to call .WAV files from any script in your application. ' Runtime Dependencies: ' Files and paths: WINMM.DLL must be installed in C:\WINDOWS\SYSTEM ' or somewhere in your current path. The sound file ' OFF2RACE.WAV must be installed in the subdirectory ' C:\WINDOWS\MEDIA. ' Declare a return value to use when you call the DLL ' function in a script. Dim SoundReturnValue As Integer ' Declare the DLL function as a public function in LotusScript. Declare Public Function sndPlaySound Lib "winmm"_ Alias "sndPlaySoundA" _ ( Byval WaveFile As String, Byval theFlags As Long ) _ As Integer ' Declare some of the constants used by parameters of the DLL function. Public Const SND_SYNC = &H0000 ' play synchronously (default) Public Const SND_ASYNC = &H0001 ' play asynchronously Public Const SND_NODEFAULT = &H0002 ' silence (!default) if sound not found Public Const SND_MEMORY = &H0004 ' pszSound points to a memory file Public Const SND_LOOP = &H0008 ' loop the sound until next sndPlaySound Public Const SND_NOSTOP = &H0010 ' don't stop any currently playing sound The following script calls the declared function and specifies a .WAV file to play.
Sub TestSoundFiles SoundReturnValue = sndPlaySound( "C:\WINDOWS\MEDIA\OFF2RACE.WAV", SND_SYNC ) End Sub End Quote See also 4. below |
|
|
|
| 5. How do I construct a dll with exported functions for 123? Rules to look out for are as follows:
|
|
| 6. How can I access the value of a cell within a range from within a custom @ function As a custom @ function in LotusScript does not allow use of object methods such
as Cell() i.e. Lets say you are given a range as input and you need to get the value of cell with coordinates (S,C,R) relative to the top left cell. ' function returns the value at sheet S from top (+ve down), C
columns to right (right +ve), R rows from top (down +ve) |
|
"ENHANCE23 " is a trademark of LAPSOFT.
"Lotus", "Lotus123" and related trademarks are trademarks of Lotus
Development Corp. www.lotus.com All other
products mentioned are registered trademarks or trademarks of their respective companies. |