Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Answered

Navision 2013 pass parameter null to Dotnet function

Posted on by 145

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

  • CristianAguerre Profile Picture
    CristianAguerre 145 on at
    RE: Navision 2013 pass parameter null to Dotnet function

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

  • Suggested answer
    Guillem Padilla Profile Picture
    Guillem Padilla 425 on at
    RE: Navision 2013 pass parameter null to Dotnet function

    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
    CristianAguerre 145 on at
    RE: Navision 2013 pass parameter null to Dotnet function

    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.

  • Verified answer
    Guillem Padilla Profile Picture
    Guillem Padilla 425 on at
    RE: Navision 2013 pass parameter null to Dotnet function

    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
    CristianAguerre 145 on at
    RE: Navision 2013 pass parameter null to Dotnet function

    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.

  • Hannes Holst Profile Picture
    Hannes Holst 5,767 on at
    RE: Navision 2013 pass parameter null to Dotnet function

    Hi,

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

    Does a Variant-variable work?

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,645 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans