Counting the number of digits in a numeric field

Discussions about CSEntry
Post Reply
Keith Tomlin
Posts: 56
Joined: March 23rd, 2014, 9:30 am

Counting the number of digits in a numeric field

Post 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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Counting the number of digits in a numeric field

Post 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
Post Reply