How can I distinguish a cell that it is blank or not while inside a user-defined function in Calc Basic?

How can I distinguish a cell that it is blank or not while inside a user-defined function in Calc Basic? For example if I want to write an “Average” function to work just like the built-in one, I’ll try to do something like this:

Public Function AverageS(A)
	Res = 0
	N = 0
   	For i = LBound(A, 1) To UBound(A, 1)
		For j = LBound(A, 2) To UBound(A, 2)
			If Not IsEmpty(A(i, j)) Then
				Res = Res + A(i, j)
				N = N + 1
			End If
		Next
	Next
	AverageS = Res / N
End Function

But NotEmpty does not do what I want it to. What should I do?

From Andrew Pitonyak’s OpenOffice.org Macros Explained 3rd Edition r523 guide (p. 470, above Listing 412):

Use the method queryContentCells(CellFlags) to obtain a list of all cells in a range that are not empty. The CellFlags argument is set to return all cells that contain a value, string, formula, or date/time.

The indicated listing provides an example of required code.