Creating user-defined functions

Function

Create a user-defined function.

Syntax

Function returning a value

Function returning no value

Detailed Description

This statement defines user-defined functions for processing shared by multiple parts of the same program.

Examples

User-defined function for adding two values
  function addfunc%( a%, b% )
    addfunc% = a% + b%
  end function

main:
  private result%
  result% = addfunc%( 200,300 )  ' call function addfunc%
  print result%                  ' displays 500
User-defined function waiting for a key press
  sub waitfunc
    private tempkey$
    print "Press a key"
    tempkey$ = input$(1)
  end sub

main:
  call waitfunc                  ' call function waitfunc
  print "A key has been pressed."
User-defined function displaying a fixed screen
  sub dispfunc( process$, UserID$ )
    print "**********"
    print process$
    print "ID:";UserID$
    print "**********"
  end sub

main:
  private PROC$
  private ID$

  PROC$ = "Inventory"
  ID$ = "10012"
  call dispfunc( PROC$, ID$ )    ' call function dispfunc
                                 ' displays Inventory
                                 ' displays ID:10012

(C)2002-2004 DENSO WAVE INCORPORATED All right reserved