How to use/initialize Dotnet Int32 type?

Slawek_Guzek
Member Posts: 1,690
Hi All,
I'd like to use standard .NET Int32 type to convert integer into hex representation (Int32.ToString('X4'))
Trouble is I cannot initialize in in C/AL?
If I create a variable of type DotNet System.Int32.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' I cannot initialize it in CAL. The line:
Can I use Int32 type at all ?
Any other simple method to convert an int into hex ?
Slawek
I'd like to use standard .NET Int32 type to convert integer into hex representation (Int32.ToString('X4'))
Trouble is I cannot initialize in in C/AL?
If I create a variable of type DotNet System.Int32.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' I cannot initialize it in CAL. The line:
DotNetInt := DotNetInt.Int32;gives an error : Assignment is not allowed for this variable.
Can I use Int32 type at all ?
Any other simple method to convert an int into hex ?
Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
0
Best Answers
-
PROCEDURE Int2Hex@1000000049(Number@1000000000 : BigInteger) Return : Code[16];
BEGIN
WHILE(Number>0) DO BEGIN
Return := COPYSTR('0123456789ABCDEF',(Number MOD 16)+1,1) + Return;
Number := Number DIV 16;
END;
END;
PROCEDURE Hex2Int@1000000050(Hex@1000000000 : Code[16]) Return : BigInteger;
BEGIN
WHILE(Hex<>'') DO BEGIN
Return := Return*16 + STRPOS('0123456789ABCDEF',COPYSTR(Hex,1,1))-1;
Hex := DELSTR(Hex,1,1);
END;
END;5 -
Hi Slawek,
you're right, impossible to work with Int32 or Int64. But you can work around it:
Use an IntPtr: IntP DotNet System.IntPtr.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
IntP := IntP.IntPtr(1234);
MESSAGE('Dec-Value='+IntP.ToString+', Hex-Value='+IntP.ToString('X4'));
Also
IntP := IntP.IntPtr(CAL_Int);
works.
Oli
2
Answers
-
If I understand correctly we dont need initialize variables in CAL.
Constructor of Int32 in CAL: static [int Int32 :=] Int32();0 -
PROCEDURE Int2Hex@1000000049(Number@1000000000 : BigInteger) Return : Code[16];
BEGIN
WHILE(Number>0) DO BEGIN
Return := COPYSTR('0123456789ABCDEF',(Number MOD 16)+1,1) + Return;
Number := Number DIV 16;
END;
END;
PROCEDURE Hex2Int@1000000050(Hex@1000000000 : Code[16]) Return : BigInteger;
BEGIN
WHILE(Hex<>'') DO BEGIN
Return := Return*16 + STRPOS('0123456789ABCDEF',COPYSTR(Hex,1,1))-1;
Hex := DELSTR(Hex,1,1);
END;
END;5 -
Hi Slawek,
you're right, impossible to work with Int32 or Int64. But you can work around it:
Use an IntPtr: IntP DotNet System.IntPtr.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
IntP := IntP.IntPtr(1234);
MESSAGE('Dec-Value='+IntP.ToString+', Hex-Value='+IntP.ToString('X4'));
Also
IntP := IntP.IntPtr(CAL_Int);
works.
Oli
2 -
Thanks oki & lynge,
lynge, a side note: your solution is not exact equivalent of int32.ToString('X4')). int32.ToString('X4')) gives you 4 character long hex string, while yours not.
Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions