Malvern Instruments makes every effort to ensure that this document is correct. However, due to Malvern Instruments
policy of continual product development we are unable to guarantee the accuracy of this, or any other document after
thedate of publication. We thereforedisclaimallliabilityfor any changes,errorsor omissions after the dateofpublication.
Noreproductionortransmissionofanypart of this publication is allowed without the express written permission of Malvern
Instruments Ltd.
Head office:
Malvern Instruments Ltd.
Spring Lane South,
Malvern.
Worcestershire. WR14 1XZ
U.K.
Tel + [44] (0) 1684-892456
Fax + [44] (0) 1684-892789
Welcome to the Malvern Basic Reference manual. This manual has been designed to give a
detailed description of the operation and use of Malvern Basic. It gives details on the structure
of a Malvern Basic program and details all commands available.
Warning: You must remember that the Zetasizer or the samples to be
measured are potentially dangerous if misused. You must read the
Health and safety booklet before operating the system.
1.2Systems covered by this manual
Zetasizer is a generic name given to a family of systems. Each system within the family uses the
same software and only vary in operation in small areas. For this reason this manual has been
written to cover more than one instrument.
Within this manual the Zetasizer system will be referred to as the “Zetasizer” or the “system”
unless the information given is for a particular instrument.
Within this manual “BASIC” will refer to the specific Malvern Zetasizer version of the language.
Any program examples wil be shown in the Courier font.
1.4Windows Terms
It is important that you understand some Windows terms before reading further. (Note that US
spelling is used for some terms for compatibility)
Program - The Zetasizer software - it can also mean the Zetasizer Basic program used within
the main Zetasizer software.
Cursor or Pointer - The graphic - usually a pointer that is moved on the screen by operation of
the mouse.
Icon - The graphic on the desktop that represents a program.
Click - The mouse button is depressed and released. If this is not qualified with a button
description then assume it is the left button. ‘Clicking a button’ means click the left mouse button
with the cursor over the button.
Double-click - Press and release the mouse button twice in quick succession. If this is not
qualifiedwith abuttondescription thenassume itis theleft button.Usethe Mouseicon inProgram
Managers Control Panel to change the double-click speed.
Dialogue Box - A window containing controls. The OK button accepts changes in the dialogue
box. The Cancel button closes the dialogue without accepting the changes.
Control - This can mean a graphic on a dialogue like a button, listbox, textbox etc.
Press or Select - This means click the mouse over a control or use the accelerator key (the
underlined letter) or use the Tab key to move the focus to a control then use the Enter key.
Menu items can be selected using the cursor keys in the same way.
Button - This acts like a real-life button. Click to carry out an action. A typical button is shown
below.
Option Button or Radio Button - A series of buttons in a group, selecting one button cancels the
others in the group. A radio button is shown below.
ILL 1992ILL 1993ILL 1994ILL 1995ILL 3864ILL 3863
Check Box - A button that can be toggled on and off. A check box is show below.
Text Box or Edit Box - A box you can type text or values into. A text box is shown below.
List Box- A box containingalist of options. SomeList Boxes allow multiple entriesto be selected.
Combination List Box or Combo Box- A combination of a list box with a text box. A buttonbeside
the text box displays or hides the list part of the control. In some cases you can type new values
into the text box part, in others the text box just shows the current selection from the list.
Drag - An action with the mouse which involves moving the mouse while holding down the left
mouse button. This is used for moving icons or making multiple selections in a list box.
1.5Menu Commands
Menu commands from the Malvern software are referred to in the form main menu-menu item.
As an example, the command File-Save Sample refers to selecting the Save Sample item in the
File menu. The same rules apply for sub-menus of sub-menus, so that Edit-Copy-Data refers to
the Data item in the Copy sub-menu, which itself is a sub-menu of the Edit menu. Menu
commands are always shown in bold text.
1.6Where to find information
The information within this manual is divided into five chapters. The information within these
chapters is summarized below.
Chapter 1 (This chapter)
Chapter 1 gives general information on the content and protocols used within this manual.
Chapter 2
Chapter 2 details the structure of a Malvern Basic program, giving details on how to write and
run a program.
Chapter 3
Chapter 3 explains how to write page description programs for views and reports. These views
and reports can then be allocated to the View menu.
Chapter 4
Chapter 4 is the main section of the manual. This section gives comprehensive details on all the
commands and functions available within Malvern Basic.
Chapter 5
Finally chapter 5 gives details of advanced features.
It should be remembered that on-line help can be gained at any point when using the Malvern
software.
1.7Reporting Problems
Beforereportinga problem pleasecheckthe relevant sectionsof the userandsoftware reference
manual, or any accessory manuals, which may have an answer. If the problem persists try to
give as much detail as possible.
If thereisaprobleminthesoftware try to give information that will allow the engineers at Malvern
to reproduce the conditions. If the problem is in the measurement or the analysis the Malvern
engineers will require a copy of the Fullsize.pcp report.
To print a Data report:
l
Change the View menu to Data.
l
Select a report print in the File - Print dialogue.
The program language used in the Zetasizer software is similar to many other variants of Basic.
Some features of other versions are not needed for our application and many extra functions
have been added for specific use in particle sizing. Throughout these notes the term Basic will
mean the specific Malvern Zetasizer version of the language.
Basic is a line interpreted language. This means that as a program is executed each line is
checked for syntax and then executed. Unless controlled to do otherwise, the execution will
continue with the next line. This means that, when you test a program, an error some way down
the program will not be reported until you reach that line.
Zetasizer Basic program examples in the manual are shown in the Courier font.
The fundamental building block of a program is the statement. This is a single instruction to
performsome action.A linein theprogrammaycontainmorethanone statement.Anystatements
on a line must be separated by colons (:).
For example :
X = 3 : Y = 2 : Z =-5
and
X=3
Y=2
Z =-5
are equivalent.
The lines of a program may be labeled. This is not necessary except when you need to refer to
a specific line from within the program itself.
The apostrophe character ( ‘ ) is used to mark comments. Any line beginning with this character
is ignored when the program is executed. Comments may be added at the end of lines using the
same character.
For example:
‘Area of a rectangle
‘Prompt for length’
10 Input “Input length”, Rectlength
‘Prompt for width’
Input “Input width” Rectwidth
The use of line numbers with tests to change the order of execution.
Basic is not case sensitive. That is, you can use upper and lower case characters in any
combination. Spaces are not significant. Thus,
RectWidth = Val ( X$ )
and
RectWidth = Val (X$ )
are equivalent.
The exception to this is that names of variables, commands, etc. may not contain spaces. You
can use
InputBox$...
Inputbox$...
inputbox$...
etc.
but
Input Box$...
will fail.
There are various standard ways to make names of variables morereadable.Theexample uses
capital letters. You can also use the underscore character. For example MeanSize or
mean_size.
2.2Building blocks of programs
The building blocks of Basic program statements are:
Commands
The commands cause actions such as “measure”, “print”, etc. They also provide means of
controlling the program by repeating loops, branching as the result of tests, etc.
Functions
The functions provide values for testing or printing.
Variables and numerical constants
The variables allow you to store and calculate with values from functions.
Operators
The operators are the means of adding, multiplying, etc. the variables and constants.
Expressions
Expressionsarethe resultofevaluating combinations ofvariables, functionsandoperators. They
may often be used as options for commands.
Commands may perform a variety of actions depending on the choice made by additional
parameters. They may also modify those actions with further parameters. Functions may be
similarly modified.
The full list of all functions and commands (over 200 items and all their variant parameters) will
not be described in detail here. The precise format of each command and function is given in
chapter 4.
Within each entry in the reference section there is the name ofthecommandorfunction followed
by ‘command’ or ‘function’ as appropriate. Remember commands perform actions and functions
give you a value to use.
2.4Constants and variables
Numbers in Basic are all real numbers (sometimes referred to as floating point numbers). There
are no integer variables. That is to say that all numbers are treated as if they contain decimal
points. The number 2.0 has the same value as the integer (whole number) 2 for all uses in the
language. If it is important to have a whole number in a particular case the language includes a
function Int() which removes the part after the decimal point. For example, Int(2.54) returns the
value 2.
Numerical values are stored to single precision giving 6 significant figures and a range of 10
to 1038.
There are also text values referred to as strings.
Constants are explicit values. For example the number 3.14159 is an explicit numerical constant
and the string “MALVERN” is an explicit text constant.
Variables contain or represent numbers or text. Again, there are no integer variables. The name
of a variable can contain up to 20 characters. The name may consist of alphabetic (A...Z, a...z)
and numeric (0 ... 9) characters, the underscore (_) or period ( . ) characters, but must start with
an alphabetic character.
Some examples of valid variable names are:
My_Variable
P.XPosition
Fi257
Some examples of invalid variable names are:
VariableComment
5FixStarts with a number.
P&GContains the & operator.
A_Very_Long_Variable_NameToo long - would be truncated.
-38
The names of variables are not case sensitive, MyVar , MYVAR and myvar would all refer to the
same variable.
There is space for 50 user variables in any program. An error is reported if this number is
exceeded. If one program calls another the variables in the calling program are not accessible
from the called program (but see below for arrays).
It is good practice to choose variable names which describe the values they will contain. This
‘self-documenting’ approach together with comments will make program maintenance and
debugging much easier.
Certain names will be disallowed. You cannot use a command or function name as a variable
name.
The names of string (text) variables follows the convention of numeric variables but the names
must end with a $ (dollar symbol). String arrays are not allowed. The total number of numeric,
array and string variables must not exceed 50 per program. The maximum length of strings must
be less than 256 characters.
Unlike some versions of Basic, the Zetasizer Basic does not require you to declare all variables
explicitly before use. A numeric or string variable is recognized the first time a value is assigned
to it. However arrays must be declared before use.
2.5Arrays
An array is a group of values referred to by a single name. The individual values in the array are
referred to by an index number.
For example MyData could be an array of 6 elements which would be referenced as MyData(0),
MyData(1), MyData(2), ... , MyData(5).
Notice that the numbering of the array is assumed to start at zero. If it is convenient for clarity to
use only the elements from number 1 onwards you can, of course, ignore element 0.
Unlike simple variables, it is necessary to declare arrays before they are used so that memory
can be reserved for them. This is done using the Dim command.
Array names follow the same rules as for simple variables. String arrays are not allowed. All
arrays are one-dimensional. That is arrays of the type X ( 3, 5 ) are not allowed.
For example:
Dim Ax ( 10 ), Ay ( 10 ), Big_List ( 1000 )
The dimension of an array is limited to 1000 (i.e. 1001 elements).
In a Dim command you may use variables and functions to specify the array sizes.
For example:
X=10
Dim A ( 2 * X + 1 )
Dim B ( StoreChannel )
are valid.
Once an array is dimensioned you may not change its dimension.
* / %Multiply, divide and modulo.
+ -Addition and subtraction.
< >=Relational operators.
>=Relational operator.
<=Relational operator.
<>Relational operator.
|Bit-wise OR operator.
&Bit-wise AND operator.
The expressions are evaluated left to right except with exponentiation which evaluates right to
left.
Unary plus and minus attach a sign to a number. For example -FirstNumber is -1 if FirstNumber
is 1, 7 if FirstNumber is -7, etc.
Exponentiation raises a number to a power. For example 3^4 is 81.
Multiply ( * ) and divide ( / ) are the normal arithmetic operations. The modulo operator calculates
the remainder after division. For example 27% 5 is 2.
Expressions involving the relational operators evaluate to 1.0 if TRUE or 0.0 if FALSE.
The AND ( & )and OR ( | ) operators convert the decimal numbers to integers before evaluation.
Therefore the expressions on either side of these operators must resolve to values in the range
0 to 65535. For example:
The simple progress from line to line of a program is very limited. In order to give the language
real power we need commands which allow us to change the order of operation according to
tests performed on variables.
In addition, the structure of the program can be simplified, the number of variables needed can
be reduced and parts of the program can be made more portable by using subroutines.
In this sense, portable means that useful sequences of instructions can be copied and pasted
into new programs.
Finally, we need to be able to repeat sequences of operations for whole sets of variables or for
a pre-defined number of times.
When the program reaches this line it evaluates the expression and if the answer is false (i.e.
the expression evaluates to 0.0) the rest of the line is ignored. Otherwise the command is
executed.
For example:
If CountsPerSec < 30000 Then Print Status, “Count Rate too small”;
Pause 5
This will check if the count rate is below 30000 and if it is will display the message in the status
bar. It will then pause for 5 seconds.
What happens if the expression is false? The message is not displayed, theprogram goes to the
next line and there is still a 5 second pause. We only want the pause if the message has been
displayed so we could write instead:
If CountsPerSec < 30000Then Print Status, “Count Rate too smalll”; :
Pause 5
This time the group of commands after Then is executed if true and ignored if false. Note that
the commands after the Then must all be on one line. The enter key should be pressed after
...Pause 5 (enter key).
We could go on in this way adding commands separated by colons. The line might then become
very long or difficult to read. In this case we could use the block form of the structure. This form
is:
If expression Then
command
....command
....
End if
Again the expression is tested and if it is true the sequence of commandsfollowing theIf ... Then
line is executed up to the line End if.
For example:
If CountsPerSec < 30000 Then
Print Status,“Count Rate too small”;
Beep
Pause 5
Print Status, Add more sample and re-run”;
End if
There is one more stage to go. Consider:
If CountsPerSec < 30000 Then
Print Status,“Count Rate too small”;
If the test is false the block is ignored and the Print Report will be executed. But, if it is true we
will get the warning and still get thePrint Report. We could get round thisin two ways. The GoTo
command could be used:
If CountsPerSec < 30000 Then
Print Status,“Count Rate too small”;
Pause 5
GoTo 20
End if
Print Report
20 ‘ This is where to continue.
The neater and clearer solution is to write:
If CountsPerSec < 30000 Then
Print Status,“Count Rate too small”;
Pause 5
GoTo 20
Else
Print Report
End if
This general form:
If expression Then
command
command
...
Else
command
command
...
End if
executes the first block of commands if the expression is true and the second block if false.
2.7.2Subroutines
Suppose that you write a test:
If CountsPerSec < 30000 Then
Print dialogue, Using, “###.### is too large”, ResultBelow (10 )
Beep
Pause 5
End if
and subsequently want to test some other parameters, say ResultAbove ( 60 ), etc. in the same
way. You could write lots of bits of code copying the above.
It is often useful to be able to perform a group of operations a number of times in a loop. To
achieve this Basic has the structure:
For variable = expression1 To expression2
...
...
Next
The counter variable is set to the value of expression1, the program lines following the For
statement are executed until the Next statement is encountered. Then, 1 is added to the counter
variable and it is compared with the value of expression2. The loop terminates when the value
of variable is greater than or equal to expression2.
If expression1 and expression2 have the same value, the loop executes once
For example:
Data_Max = - 1000
For i = 1 To NumChannels
If StoreChannel ( i ) > Data_Max Then Data_Max = StoreChannel ( i )
Next
This will check through the data to find the maximum value.
Avoid changing the value of counter within the loop. Changing the loop counter is poor
programming practice; it can make the program more difficult to read and debug.
The counter variable may be just that. For example:
For i = 1 To 4
Measure Sample
Calculate
Print Report
Next
Sometimes we may want to step through a set of values using, for example, every other one. To
do this we can use the extended form of this command structure
For variable = expression1 To expression2 Step expression3
...
...
Next
This time instead of increasing the variable by 1 each time the Next is reached it is increased by
the value of expression3.
For example:
OpenFile “standard”
‘Read the number of records in the file.
LastRecord = Numrecords
‘Process pairs of records to show differences between 1 & 2, 3 & 4,
etc.
DifferenceRecord i + 1
View Difference
Pause 10
Next
2.7.4Nesting
Control structures may be nested, that is placed one inside another. If .. Then can be placed
inside For ... Next loops as seen above, or vice versa. If ... Then can be placed inside another If
... Then as below:
If CountsPerSec < 30000 Then
Print Status, “Count rate too smalll”;
Pause 5
GoTo 20
Else
If ResultValid Then
Print Report
Else
Print dialogue, “Result invalid”
End if
End if
Similarly, For ... Next loops can be placed inside other For ... Next loops.
For i = 1 To 5
For j = 1 To 8
Move 20 * i, 10 * j
Box 20 * i + 19, 10 * j + 9
Next
Next
There are limits placed on the number of levels to which you can nest structures. For example,
For ... Next loops can be nested to 25 levels. None of the limits should cause you any practical
problems !
You can see from the above examples that it would be easy, in complex structures, to lose track
of the match between For and its corresponding Next or between the parts of If ... Then ... Else
... End if You can help to avoid this by indenting each block of statements as in the examples.
2.8Special programs in Zetasizer Basic
The Zetasizer Basic language is used, not only to provide control and calculation routines, but
also as the standard method of producing result tables and reports. It is also used for special
programs to perform remote reporting and DDE linking.
For a detailed description of the use of Malvern Basic in page design see chapter 3. For DDE
linkingsee ‘DynamicDataExchange’ inthe SoftwareReferenceManualandforremoteoperation
see ‘Remote’ in the Software Reference Manual.
A program may also be run automatically when the Zetasizer software is first started. This may
be used, for example, to automatically start a measurement sequence. See Control-Assign
Program in the Software Reference Manual for more information.
2.9Functions- a review
There are over 220 functions available but they will not all be dealt with individually here. For
precise details on every function please consult chapter 4.
Page layout functions allow you to design pages by spacing rows and columns of figures in a
way which is best adapted to the specific output device. For more details of page design see
chapter 3.
Result information functions allow you to use values which describe the size distribution.
Sample documentation functions record the Sample identifier, Sample Notes and run number
for accurate identification of the information on print-outs.
Hardware information records the specific settings of hardware used in the measurement.
Software settings give the parameters used in analysing the data.
2.10Writing andrunningprograms
2.10.1Recording a program
If you intend to write a program that controls the Zetasizer measurements or process sample
records you may find it convenient to record the basic outline of the program.
There are two modes of recording - if you elect to Fill in dialogue Boxes then the Zetasizer will
act normally but all your commands will be recorded. If you do not select Fill in dialogue Boxes
then the normal action of the commands will not be carried out - the program will record only the
commands that were actioned.
See the Control-Record Program command in the Software Reference Manual for more
information.
2.10.2Editing a program
A recorded programmaybemodifiedora new program may be written using the program editor.
Theprogram editoris aseparatewindow thatis alsoused forentering pageand reportdescription
programs. To edit a normal program the editor window is produced by selecting the Control-Edit
Program command.
The editor window has its own menu bar.
Menu itemFunction
File-NewEdit a new program
File-LoadLoad a program from disk
File-SaveSave a program to disk
File-Save AsSave a program with a new name
File-ExitClose the editor window
Edit-UndoUndo the last edit
Edit-CutCut the selected text to the clipboard
Edit-CopyCopy the selected text to the clipboard
Edit-PastePaste at the cursor the text in the clipboard
Edit-DeleteDelete the selected text
The first time you run a program you should use the Run button in the Program Editor. If there
are any mistakes or errors then the cursor will move to the line with the error.
When the program is debugged it may be saved on disk (preferable in the PROGRAMS
subdirectory). The program may then be run from the Control-Run Program command (See the
Software Reference Manual for details).
2.10.4Assigning Programs to Keys and Menu
The Control-Run Program command allows a single program to be run several times without
having to pick it from the list of all the programs. If you have several programs you wish to run
you may want to assign them to the end of the Control menu. An assigned program can be run
either by selecting the entry from the Control menu or by using the function keys F5 to F8 (or
those keys in combination with the control and shift keys).
See the Control-Assign Program command in the Software Reference Manual for more
information.
2.11Program Errors
Therearetwo types oferrorsinvolved in usingtheZetasizer programming language. Firstlythere
are errors caused by mistakes in the construction of your program. For example the statements:
IfX>0
GoTo 100
End if
will produce the error “THEN expected” because the first line is incomplete.
A list of these errors is given below. To correct such an error, consult the details of the particular
command or function, if necessary, correct the error and re-run the Program.
The second type of error occurs when you run the Program. For example, if you attempt to use
the command:
Load Record N
and the expected record cannot be loaded for some reason, the system will return an error code
which you can use to make decisions about the next action:
Load Record N
If Error = 0 Then
Print Report
Else
X = Print Dialogue “Record no found”
End
End if
The values of any error codes which might be returned and their meanings are shown in the
description of each individual command and function.
2.11.1Basic Errors
The message displayed at the top of the program editing box gives you information about the
type of error which has occurred. If the message is Syntax error in line n then inspect the line to
ensure that the commands, functions, etc. are correctly spelled.
Specific error messages are :
Unbalanced parentheses
The number of left and right parentheses do not match. For example
X= Int ( ( N - 1 ) / 2
Correct to
X = Int ( ( N - 1 ) / 2 )
No expression present
A value was expected.
Equals sign expected
The line is interpreted as beginning with a variable name but does not have a value assigned.
This often occurs when an incomplete line is entered or a command is mis-spelled.
For I = 1 to 5
Load Record 5
Print Report
Nxt
Correct the last line:
Next
Label table full
You may use up to 100 labels. Your program contains more than this number. To correct this
you will need to simplify the structure of the program to use less labels. Using If... Then ... Else
structures to replace GoTo may help.
Duplicate label
You have used a label more than once. To correct this change one of the labels.
Undefined label
There is a Goto or Gosub which uses a label which you have not included in your Program. To
correct this check that you have typed the label correctly. Add the required label if necessary.
THEN expected
There is an If statement which is incomplete. For example:
IfX>0
GoTo 100
End if
Correct to
If X > 0 Then
GoTo 100
End if
TO expected
There is an error in the For statement. For example:
For I = 1, 10
Correct to
For I=1 To 10
Too many nested FOR loops
For ... Next loops may be nested to a maximum of 25. Your program structure is too complex.
NEXT without FOR
Each blockofstatements beginning For ...must end with acorresponding Next. The error ismost
easily caused when nesting several levels of For ... Next loops or when code has been cut and
pasted incorrectly.
Too many nested GOSUBS
When you call a subroutine you may call anothersubroutinebeforereturningto theoriginal point
in the Program. This process can continue up to 25 levels. This error indicates that you have
exceeded the limit. Your Program structure is too complex.
RETURN without GOSUB
The most common cause of this error is not including an End statement. For example
For I = 1 to 10
GoSub 100
Next
100
Load Record I
Print Report
Return