I'm trying to call a DotNet function:
long.TryParse(hexNumber, System.Globalization.NumberStyles.HexNumber, null, out result);
I have problems to the null parameter, how I can pass null to Dotnet from Navision?
Thanks in advance
I'm trying to call a DotNet function:
long.TryParse(hexNumber, System.Globalization.NumberStyles.HexNumber, null, out result);
I have problems to the null parameter, how I can pass null to Dotnet from Navision?
Thanks in advance
@Guillem Padilla,
It works! When I tried to use IformatProvider solution I selected by error IFormatable (sorry for the mistake).
To use the out paremeter you only need pass a varible with the correct type (in this case integer).
Here the code example and variable definitions:
//Variable definition
long | DotNet System.Int64.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' |
NumberStyle | DotNet System.Globalization.NumberStyles.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' |
TextOutVarTypeText | Integer |
NumberHex | Text |
IFormatProvider | DotNet System.IFormatProvider.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' |
//Code Example
NumberHex := '#FF0000'; //METHOD SIGNATURE: // [bool TryParse :=] long.TryParse(string s, ref long result) long.TryParse(NumberHex, TextOutVarTypeText);//compile OK //METHOD OVERLOAD SIGNATURE: //[bool TryParse :=] long.TryParse(string s, System.Globalization.NumberStyles style, IFormatProvider provider, ref long result) long.TryParse(NumberHex, NumberStyle.HexNumber, IFormatProvider, TextOutVarTypeText)
@Guillem Padilla thanks for your help.
Best regards.
Hello,
I have reproduced the error and it seems that it is because of the out result parameter, if you call
long.Parse(HexNumber, System.Globalization.NumberStyles.HexNumber, IFormatProvider);
IFormatProvider being null
It does not give compilation errors ...
You will see that it works correctly, I have checked it.
Actually, with this, the doubt about how to pass null as a parameter is resolved.
The problem is that now another question arises, how to handle out result
How are you handling the returned value?
Hi @Guillem Padilla,
Your solution sounds really good but didn't work.
I tried and the system throws error "The call is ambigous" when I try to compile the object.
Thank you for your time.
Best regards.
Hi,
You should make a DotNet variable of the same parameter object type, in this case you want to null the IFormatProvider parameter
You can get it in mscorlib assembly System.IFormatProvider
If you execute MESSAGE(FORMAT(IFormatProvider)), you will get null value, so I think that you can do:
long.TryParse(hexNumber, System.Globalization.NumberStyles.HexNumber, IFormatProvider, out result);
Please, try this and share if it worked
Thanks!
Hi @Hannes Holst ,
I tried with variant and didn't work, I tried with a DotNet mscorelib System.Object and do not assign value to be null and eather.
Finally (I don't think is the best solution...) I create my own Dotnet and put the call in my own method (my method not need parameter null ;-) ) .
If anywone know best way to do it please share :)
Best regards.
Hi,
That looks like a parameter with a lot of sense :-)
Does a Variant-variable work?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,558 Super User 2024 Season 2
Martin Dráb 228,645 Most Valuable Professional
nmaenpaa 101,148