web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Navision 2013 pass parameter null to Dotnet function

(0) ShareShare
ReportReport
Posted on by 147

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

*This post is locked for comments

I have the same question (0)
  • Hannes Holst Profile Picture
    5,767 on at

    Hi,

    That looks like a parameter with a lot of sense :-)

    Does a Variant-variable work?

  • CristianAguerre Profile Picture
    147 on at

    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.

  • Verified answer
    Guillem Padilla Profile Picture
    427 on at

    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!

  • CristianAguerre Profile Picture
    147 on at

    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.

  • Suggested answer
    Guillem Padilla Profile Picture
    427 on at

    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.

    longparse.JPG

    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?

  • CristianAguerre Profile Picture
    147 on at

    @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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans