base - how to test if numerical field on a form is empty

Hi,

How to properly test if a numerical field on a form is empty?

I’ve tried a few options, first with a newly initialized form. Then I entered a value in the textbox and deleted it immediately. Then I ran the test a second time.

isNull

if isNull(oNumericalBox.value) then
	msgbox "isNull true, value= " & oNumericalBox.Value
else
	msgbox "isNull false, value= " & Cstr(oNumericalBox.Value) 'Cstr used to avoid an error
endif

'--> output 1st time: isNull false, value= 
'--> output 2nd time: isNull false, value= 0

isEmpty

if isEmpty(oNumericalBox.value) then
	msgbox "isEmpty true, value= " & oNumericalBox.Value
else
	msgbox "isEmpty false, value= " & oNumericalBox.Value
endif

'--> output 1st time: isEmpty true, value= 
'--> output 2nd time: isEmpty false, value= 0

= 0

if oNumericalBox.value = 0 then
	msgbox "= 0 true, value= " & oNumericalBox.Value
else
	msgbox "= 0 false, value= " & oNumericalBox.Value
endif

'--> output 1st time: = 0 true, value= 
'--> output 2nd time: = 0 true, value= 0

It seems these three tests cannot be used to detect an empty numerical textbox or to differentiate between an empty textbox or a textbox with value = 0.

So what should I use instead?

tnx

ps using LO 6.2.8.2 (downloaded from the LO website) on Linux Mint 18.3 mate

Did you find the answer? because I have the same question… Seems like an annoying bug

Which bug? All @stabiloboss showed seems to indicate his value is not empty in is second test but has a number zero aka 0 as value - this is different from SQL NULL…

Value in a numerical field is empty, if there is no entry.
Test this with a numerical field and mouseclick in the field:

SUB TestField(oEvent AS OBJECT)
	oField = oEvent.Source.Model
	IF IsEmpty(oField.Value) THEN
	   msgbox "Hallo"
	ELSE
	   msgbox oField.Value
	END IF
END SUB

If you type something in this field it won’t show “Hallo”. If you remove it (Backspace or Del) (and it isn’t visible any more) it is still there. You could only clear this value by remove the whole data input of the form.

This is a bug, but I never seen it is reported.

@RobertG, we can check the oEvent.Source.Text property.

This has nothing to do with macro code:
InsertRemove.odb (11.9 KB)
Download the file.
Open the form.
Write ID: 1
Name: Hallo
Age: 27
and remove the content of “Age” with Back.
Go to next row.
Content will be saved, go back and “Age” will show ‘2’ instead of none.

Now do the same with Del instead of Back.
“Age” will show ‘7’ instead of none.

Buggy behavior appears here with LO 7.6.2.1 on OpenSUSE 15.4 64bit rpm Linux.

Have wrote a bug description for this: Bug 157805

@sokol92 : Property “Text” will only show what you see in the form. But the buggy behavior is: There is a value in the field, which is shown as a blank field.
A formatted field (instead of a numeric field) will work well. You have to change macro to “CurrentValue” instead of “Value”, and it will switch back to “IsEmpty” if there is no content to save. Field will be saved with NULL in the database.

3 Likes