Page 1 of 1

Counting the number of digits in a numeric field

Posted: February 22nd, 2015, 1:37 pm
by Keith Tomlin
Hi - is there a function which can count the number of digits in a numeric item and give an error message if the number of digits is below a required amount? In my application I am using numeric fields with a length of 8 to record dates. The dates are in the format DDMMYYYY. I use a sub-item for the Year part in subsequent calculations, and so the dates entered have to be eight digits long for the calculations to work. I am working with the Ethiopian calendar, and so the date picker control isn't an option. From what I can tell the Length function only applies to strings. Would I need to convert the numeric item to a string first before determining how long it is? I've explored the edit function to to do this, but I'm not quite sure how to use the syntax.

Any help very gratefully received.

Many thanks

Keith

Re: Counting the number of digits in a numeric field

Posted: February 23rd, 2015, 1:21 pm
by josh
You could use the maketext function and then take the length of the string:

Code: Select all

length(maketext("%d", myvar))
Alternatively if you want 8 digits then you could just use numeric comparison with 10^8:

Code: Select all

if myvar < 10000000 then
  errmsg("too short");
endif