Convert
Functions in ax 2012
1.any2Enum
Function
Converts an anytype value to the Name property value of an element in the
target enum.
Syntax:
enum
any2Enum(anytype object)
The value of the Name property for whichever element on the
target enum has a Value property
that matches the input parameter.
The object parameter can be of most data types, but
useful data is only obtained by using a parameter of type str or int.
This input object parameter refers to the Value property of an individual element in the
target enum.
Example:
NoYes
myNoYes; //
NoYes is an enum.
int i;
str s;
i = 0; // An int that will be converted.
myNoYes
= any2Enum(i);
Global::info(strfmt("'%1' - is the output, from input of the %2 as
int.", myNoYes, i));
s = "1";
// A str that will be converted.
myNoYes
= any2Enum(s);
Global::info(strfmt("'%1' - is the output, from input of the %2 as
str.", myNoYes, s));
OP: 'No' - is the output, from input of the 0 as int.
'Yes' - is the output, from input of the 1 as str.
2.any2Date Function:
Converts an anytype value to a date value.
Syntax: date any2Date(anytype object)
Note:-Object:The value to convert to a date.
Example:
date getdate;
str s;
int i
;
s="2012 2 12"; //yyyy mm dd
getdate=any2date(s);
{
info(strFmt("%1",getdate));//OP:2/12/2012
}
i=40361;
getdate=any2date(i);
{
info(strFmt("%1",getdate));//Op:
7/4/2010
}
3.any2Guid Function:
Converts the
specified anytype object to a GUID object.
Syntax: guid any2Guid(anytype object)
4.any2Int Function :
Converts an anytype value to an int value.
Syntax: int any2Int(anytype object)
5.any2Int64 Function:
Converts an anytype object to an int64 object.
Example:
int Sint;
str s;
NoYes
Ny;
real re;
;
s="55";
Sint=any2int(s); or Sint=any2int64(s);
info(strFmt("%1",s));//op:55
Ny=NoYes::Yes;
Sint=any2int(Ny);
info(strFmt("%1",Sint));//Op:1
re=5.99;
Sint=any2int(re);
info(strFmt("%1",Sint));//Op:5
6.any2Real Function:
Converts an anytype value to a real value.
Syntax:
real any2Real(anytype object)
Example:
real Re;
str s;
int i;
NoYes
ny;
;
s="5.66";
Re=any2real(s);
info(strFmt("%1",Re));//Op:5.66
i=99;
Re=any2real(i);
info(strFmt("%1",Re));Op:99.00
ny=NoYes::No;
Re=any2real(ny);
info(strFmt("%1",Re));Op:0.00
7.any2Str Function:
Converts an anytype value to a str value
Syntax:
Str any2str(anytype
object)
Example:
str mystring;
anytype a;
NoYes
ny;
int i;
;
a="delhi64";
mystring=any2str(a);
info(strFmt("%1",mystring));//Op:delhi64
a=NoYes::No;
mystring=any2str(a);
info(strFmt("%1",mystring));
Op:0(because it is the value of specified enum
element)
8.char2Num Function:
Converts a
character in a string to the ASCII value of the character.
Syntax:
int char2Num(str text, int position)
Example:
int i;
str s;
;
s="shiva";
i=char2num(s,5);
info(strFmt("%1",i));
Op:97
9.date2Num Function:
Converts a date to
an integer that corresponds to the number of days since 1 January, 1900.
Syntax: int date2Num(date _date)
_date:date to convert;
Example:
date d;
int i;
;
d=today();
i=date2num(d);
info(strFmt("%1",i));
or
i=date2num(29\04\2015);
info(strFmt("%1",i))
Op: 42121
Note: Retrives the number
of days between from 1 January, 1900 and the specified date.
10.date2Str Function:
Converts the
specified date to a string
Syntax: str date2Str(
date date,
int sequence,
int day,
int separator1,
int month,
int separator2,
int year
[, int flags = DateFlags::None])
|
Parameter
|
Description
|
|
date
|
The
date to convert.
|
|
sequence
|
A
three digit number that indicates the sequence for the components of the
date, 1 for day, 2 for month, and 3 for year.
|
|
day
|
A DateDay enumeration value that indicates the format for the day
component of the date.
|
|
separator1
|
A DateSeparator enumeration value that indicates the separator to use
between the first two components of the date.
|
|
month
|
A DateMonth enumeration value that indicates the format for the
month component of the date.
|
|
separator2
|
A DateSeparator enumeration value that indicates the separator to use
between the last two components of the date.
|
|
year
|
A DateYear enumeration value that indicates the format for the
year component of the date.
|
|
flags
|
A DateFlags enumeration value that indicates whether the language
settings on the local computer should be used to calculate the proper
left-to-right or right-to-left sequence in the returned string.
|
A
string that represents the specified date.
Example:
date Todaydate=today();
str s;
;
s=date2str(Todaydate,123,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator
::Slash,DateYear::Digits4);
info("today is"+s);Op:29
or
//date Todaydate=today();
str s;
;
s=date2str(Today(),123,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator
::Slash,DateYear::Digits4);
info("today’s date is" +s);
Op: today’s date is 29/04/2015
11.datetime2Str Function:
Converts a utcdatetime value into a string.
Syntax: str datetime2Str(
utcdatetime datetime
[, int flags = DateFlags::None])
Example:
utcdatetime utc2 = 1959-06-17T15:44:33;
str s3;
;
s3 = datetime2Str( utc2 );
info( s3
);
Op: 4/29/2015 03:44:33 pm
12.formattedStr2Num:
Converts a semi-numeric
string into a real number.
Syntax:real formattedstr2Num(str _text)
Example:
print formattedstr2Num("123.45");//Op:123.45
pause;
or
real r;
r=formattedstr2Num("123");
info(strFmt("%1",r));//Op:123.00
or
int i;
i=formattedstr2Num("123.01");
info(strFmt("%1",i));Op:123
or
print formattedstr2Num("356890");
pause;//Op:356,890.00
or
print formattedStr2num("12+1200");
pause;Op:12,12.00
13.guid2Str Function:
Converts the
specified GUID object to the equivalent string.
Syntax: str guid2String(guid _uuid)
Example:
guid _guid;
str stringGuid;
;
_guid =
Global::guidFromString
("{12345678-1234-1234-1234-123456789abc}");
print strfmt("GUID is %1", _guid);
stringGuid = guid2str(_guid);
info("String GUID is " + stringGuid);
Op: String GUID is {12345678-1234-1234-1234-123456789ABC}
14.int2Str Function:
Converts an integer
to the equivalent string.
Syntax:
str int2Str(int integer)
15.int642Str Function:
Converts the specified integer parameter to the equivalent text string.
Syntax: str int642Str(int64 integer)
Example:
str s;
int i=64;
;
s=int2str(i);
info(strFmt("%1",s));Op:64;
or
info ("This is int2Str, value is " + int2Str(intMax()));
info ("This is int642Str, value is " + int642Str(int64Max()));
Op: This is int2Str, value is 2147483647
This is
int642Str, value is 9223372036854775807
16.str2Int Function:
Converts a string
to the equivalent integer.
Syntax: int str2Int(str _text)
Example:
int i;
str s="65";
;
i=str2int(s);
info(strFmt("%1",s));//Op:65
17.num2Char Function:
Converts an integer
to the corresponding ASCII character.
Syntax: str num2Char(int figure)
Example:
str s;
s=num2char(35);
info(strFmt("%1",s));//Op:#
18.num2Date Function:
Retrieves the date
that corresponds to the specified number of days after 01\01\1900.
Syntax:
date num2Date(int _days)
Example:
date s;
s=num2date(36356);
info(strFmt("%1",s));
OP: 7/17/1999
19.num2Str Function:
Converts a real
number to a string.
Syntax: str num2Str(
real number,
int character,
int decimals,
int separator1,
int separator2)
Example:
real num=0.1234567891123456;
info(num2str(num,0,10,1,3));//OP: 0.1234567891
info(num2str(num,0,17,1,3));//OP: 0.12
20.str2Enum Function:
Retrieves the enum
element whose localized Label property value matches the input string.
Syntax: enum str2Enum(enum _type, str _text)
Example:
BankAccountType
bat;
str sEnumValueLabelLocalized;
int nInt;
// enum2str.
sEnumValueLabelLocalized = enum2str
(BankAccountType::SavingsAccount);
info("Localized friendly string: "
+
sEnumValueLabelLocalized);
// str2enum.
bat = str2Enum(bat, sEnumValueLabelLocalized);
nInt =
bat;
info("nInt = "
+ int2str(nInt));
Op: Localized friendly string: Savings account
nInt = 1
21.str2Date Function:
Converts the
specified string to a date value.
Syntax:
date str2Date(str _text, str _sequence)
|
text
|
The string to convert to a date value.
|
|
_sequence
|
A three digit
integer that describes the positions of the day, month, and year in the
string to convert.
|
Use
the following values to specify the positions of the day, month, and year in
the _sequence parameter:
·
day: 1
·
month: 2
·
year: 3
Example:
date d;
d=str2Date("02/11/2012",123);
info(strFmt("%1",d));
Op:
2/11/2012
22.str2Datetime Function:
Generates a utcdatetime value from the specified string of date and time
information.
Syntax:
utcdatetime str2datetime( str text, int sequence )
Example:
utcdatetime utc3;
str sTemp;
;
utc3 = str2datetime( "1985/02/25
23:04:59" ,321 );
sTemp = datetime2str( utc3 );
//print( "sTemp == " + sTemp );
info(sTemp);
Op: 2/25/1985
11:04:59 pm
23.str2Guid Function:
Converts a string
to a GUID object.
Syntax:
Guid str2Guid(str text)
24.str2Int64 Function:
Converts a string
into an Int64 value.
Syntax:
int str2Int64(str text)
Example:
str myStr;
str tooBig;
Int64 myInt64;
;
myStr = "1234567890";
tooBig =
int642str(int64Max()+1);
myInt64
= str2Int64(mystr);
info (strfmt ("int64:
%1",myInt64));
myInt64
= str2Int64(tooBig);
info(strfmt ("Too
big int64: %1",myInt64));
Op: int64: 1234567890
Too big
int64: -9223372036854775808
25.str2Num Function:
Converts a string
to a real number.
Syntax: real str2Num(str _text)
Example:
str s="12.45";
real r;
r=str2Num(s);
info(s);
Op:12.45
26.str2Time Function:
Converts a string
to a timeOfDay value.
Syntax: int str2Time(str _text)
Note:The number of seconds between
midnight and the _text parameter; otherwise, -1.
Example:
int i;
i=str2time("2:31");
print i;
pause;
Op: 9060
27.time2Str Function:
Converts a timeOfDay value to a string that includes hours, minutes, and
seconds.
Syntax:
str time2Str(
int _time,
int _separator,
int _timeFormat)
Example:
timeOfDay theTime = timeNow();
;
info( time2Str(theTime, TimeSeparator::Colon,
TimeFormat::AMPM) );
Op: 06:22:37 pm
28. uint2Str Function:
Converts an integer
to a string with the assumption that the integer is unsigned.
Syntax:
str uint2Str(int integer)z
Example: info(int2str(3123456789)); //-1171510507