Page 1 of 1

Is it text or number (TI Question)

Posted: Mon Jul 15, 2013 9:46 am
by TomHine
Hi,

I'm using TM1 9.5 and writting a new TI process for data import.

The system I'm importing from is a single ledger system and therefore when I extract the data it shows all the nominals with balances but also all of the debtor/creditor accounts. All of the dr and cr accounts begin with a letter whereas all of the nominal accounts start with a number.

I'd like to consolidate the dr and cr accounts by using a if formula to ascertain whether the string starts wiht a letter or a number. Does such a function exist in the functions, I can't see one?

Regards

Tom

Re: Is it text or number (TI Question)

Posted: Mon Jul 15, 2013 9:50 am
by David Usherwood
I'd suggest picking up the first character using subst(xxx,1,1) and testing whether it is between 0 and 9 inclusive.

Re: Is it text or number (TI Question)

Posted: Mon Jul 15, 2013 9:54 am
by Alan Kirk
TomHine wrote:Hi,

I'd like to consolidate the dr and cr accounts by using a if formula to ascertain whether the string starts wiht a letter or a number. Does such a function exist in the functions, I can't see one?
You can use the Code Rules function to determine the ASCII code of the first character. If the code falls between 48 and 57 inclusive, it's a digit.

Edit: 3 independent replies within 4 minutes. That's service with a smile.

(David beat me only because the Reference guide was really slow to provide the link tonight. ;) )

Re: Is it text or number (TI Question)

Posted: Mon Jul 15, 2013 9:54 am
by Wim Gielis
Hi Tom

Code: Select all

If(Code(youraccount,1)>=48 & Code(youraccount,1)<=57);
# this is a number
EndIf;
or:

Code: Select all

If(Subst(youraccount,1,1)>='0' & Subst(youraccount,1,1)<='9');
# this is a number
EndIf;

Re: Is it text or number (TI Question)

Posted: Mon Jul 15, 2013 9:55 am
by Wim Gielis
Or another variation:

Code: Select all

If(Scan(Subst(youraccount,1,1),'0123456789')>0);
# this is a number
EndIf;

Re: Is it text or number (TI Question)

Posted: Mon Jul 15, 2013 1:13 pm
by lotsaram
Wim Gielis wrote:Or another variation:

Code: Select all

If(Scan(Subst(youraccount,1,1),'0123456789')>0);
# this is a number
EndIf;
Awesome code snippet.

Re: Is it text or number (TI Question)

Posted: Tue Jul 16, 2013 9:30 am
by AmbPin
If you wanted to check the whole string one way might be:-

Code: Select all

sTestString = '1234a';

nStringPos = 0;
While(nStringPos < Long(sTestString) & nStringPos > -1);
  nStringPos = nStringPos + 1;
  If(Scan(SubSt(sTestString, nStringPos, 1), '0123456789') = 0);
    nStringPos = -1;
  EndIf;
End;

If(nStringPos > 0);
# This is a number.
EndIf;