DIAdem Help

Function Procedure

  • Updated2024-09-12
  • 2 minute(s) read

Function Procedure

The Function procedure is a sequence of script statements enclosed by the keywords Function and End Function. A function procedure is similar to a Sub Procedure, but can return a value. A value is returned when a value is assigned to a function name in one or more of its instruction lines. The return value type is always a variant. A function procedure can accept arguments, which include constants, variables, or other expressions, that are transferred from a calling procedure.

Function Name ([ArgList])
  [Statements]
  [Name = Expression]
End Function
NameName of the function procedure. The name can contain a maximum of 255 characters and must begin with a letter of the alphabet. Embedded periods or type declaration characters are not valid.
ArgListList of the arguments that are transferred to the function procedure when called. You separate multiple variables with commas. Use the keywords ByRef and ByVal to specify whether arguments are transferred as values or as references.
StatementsAll statements in a procedure are enclosed by Function and End Function .
ExpressionReturn value of the function.

In the following example, the Celsius function calculates from a Fahrenheit temperature the respective value in degrees Celsius. The function call in the main part of the script transfers a variable with the argument value to the function. The calculation result is assigned to a variable and displayed in a message box:

Function Celsius(DegF)
  Celsius = (DegF - 32) * 5 / 9
End Function
Temp = InputBox("Please enter temperature in F")
TempC = Celsius(Temp)
Call MsgBox("Temp= " & TempC & " Degrees Celsius")

To use a function procedure in a script, you must use the procedure on the right side of a variable assignment or in an expression.

TempC = Celsius(Temp)

Or:

Call MsgBox("Temp= " & Celsius(Temp)&" Degrees Celsius")

Related Topics

Class | Const | Function | Sub | Property Get | Property Let | Property Set | ByRef - ByVal