Page 1 of 1

isnumber Function

Posted: Mon Jul 13, 2015 1:57 pm
by WallyD444
Is there a comparable function to isnumber in GAD? I'm trying to base an if statement on whether the variable returned is a number (0-9), I've tried this:

${decimal(fnameChar)==1 OR decimal(fnameChar)==2 OR decimal(fnameChar)==3 OR decimal(fnameChar)==4 OR decimal(fnameChar)==5 OR decimal(fnameChar)==6 OR decimal(fnameChar)==7 OR decimal(fnameChar)==8 OR decimal(fnameChar)==9}

but it fails with this error: [8099 - print] An unexpected error occurred. Function 'Decimal': Parameter '1' must be a number. Function definition: 'Decimal(number) returns decimal'

I assume it's because the variable fnameChar is a 't'. I was hoping it would say 'well, "t" is not a 1 or 2 or ect. . .' and carry on.

Any advice on this? thank!

Re: isnumber Function

Posted: Mon Jul 13, 2015 4:09 pm
by Support_Rick
WallyD...

There isn't an "IsNumeric" function currently built into GAD. There are 2 options though.

1. Take advantage of an SQL Function like MSSQL IsNumeric() and return the value (condition) you're looking for then continue as needed.

2. Use the Utility below that I created some time ago ... it will help you identify whether or not the value passed into the Utility is Numeric or not.

**NOTE** .. this can be tweaked to include decimals, etc. Currently set for whole numbers only.
Code: Select all
<project name="IsNumeric" mainModule="Main" version="2.0" logLevel="silent">

	<module name="Main">

		<raiseError label="Have MyVal?" version="1.0" executeOnlyIf="${ IsEmpty( MyVal ) }">
			<message>MyVal cannot be blank!  Try again ...</message>
		</raiseError>

		<setVariable label="Setvar: IsNumeric" name="IsNumeric" value="${ If( IsEmpty( Replace( MyVal , &apos;[0-9]&apos;, &apos;&apos;)), true, false ) }" version="2.0" />


		<print label="Status" version="1.0">
			<![CDATA[
====================================
MyVal: ${MyVal} -- is Numeric? ${IsNumeric}
====================================]]>
		</print>

	</module>

	<variable name="MyVal" value="" />
</project>

Re: isnumber Function

Posted: Tue Jul 14, 2015 11:26 am
by WallyD444
Perfect, thank you!!