fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC:

_Val() function xsharp.core 22 Feb 2021 11:12 #17528

  • info@task.si's Avatar


  • Topic Author


  • Posts: 17
  • Hi all !
    Env. Xsharp 2.7 public
    As I understand _Val(string) Function returns obj. In Core dialect there is no truncate function (like ConvertToInt32() in C#).
    So, to convert string to usual and later to integer. we must use Val() function from XSharp.RT.
    My question are:
    a) Is there anything undocumented in Core.dll ?
    b) What is impact of using two (or more) X# dll on final executable. Is final code "overweighted". My question explicitly adresses problem that till this moment a Val() function is the only funct. that I need it from XSharp.RT.dll ?
    TIA Andrej

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 11:48 #17531

  • Chris's Avatar

  • Chris


  • Posts: 2346
  • Hi Andrej,

    Everything defined in the framework that you can use in c# can also be used by X#. This works fine:

    ? Convert.ToInt32("123")

    same with other similar parsing methods like Int32.Parse(), System.Double.Parse() etc.

    So you can simply use those, instead of the _Val() function, which was designed to translate numeric data from dbf fields, and also supports the special quirks Visual Objects has in this area of conversions, which is something I guess you do not need.

    So no reason for you to use the runtime dlls, but to answer your question, if the dialect you have selected for your project is "Core", then simply referencing the runtime dlls does not have an impact on your executable. In fact, the dlls are not even loaded at runtime in memory at all, until you actually do use something (like a function) from those dlls.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    _Val() function xsharp.core 22 Feb 2021 14:20 #17532

  • info@task.si's Avatar


  • Topic Author


  • Posts: 17
  • Hi and thank you Chris !

    I can't find Convert.ToInt32(string) in the XSharp Runtime Documentation !
    Using Convert.ToInt32(string) in my program I get XS0029 error :
    error XS0029: Cannot implicitly convert type 'int' to 'string' 524,5 Start.prg SysKey:.ctor

    note: SysKey is my class where I read data from my MSSql Table using DataAdapter
    What is missed ?

    I understand your answer about loading dll. My problem is that I use X# as a project in my VS 2019 Blazor solution. When the solution is compiling I can see that both Xsharp libraries are "touched". So it worries me a little if everything will be OK (in real world or in different OS).
    Andrej

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 15:03 #17533

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2520
  • Hi Andrej,
    of course this method is not documented in the X# documentation as it is a method of the .NET Framework.
    You should look in the Microsoft documentation for it.
    You will need to include the "System" library in your application.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 15:33 #17535

  • Chris's Avatar

  • Chris


  • Posts: 2346
  • Hi Andrej,

    This error message does not seem to be related to Convert.ToInt32() itself, but some other part of the code. What is the exact line of code for which the compiler reports this error?

    Regarding the libraries, what do you mean with "touched"?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 16:11 #17536

  • info@task.si's Avatar


  • Topic Author


  • Posts: 17
  • Thank you Wolfgang and Chris !
    Documentation: .NET (now I understand)
    using Convert.ToInt32 --> no errors more; mistake in my variable declaration

    Chris: During compilation in VS in the footer line you may notize different phases, stages of compilation. And off course because XSharp project (source code) is a part of a final solution , I can see also XSharp.Core dll for a moment that is "touched".

    TIA Andrej

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 17:40 #17537

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2520
  • Hi Andrej,
    I have many projects in X# that don't use X# runtime DLLs at all - partly their were written before the X# runtime was ready.
    Therefore they don't use any X# DLL, and only .NET Framework functionality.
    it is like working with C# but using my favorite language - clear and easy to understand, without counting of parentheses and semicolons.
    Most of them are WPF applications, some Windows services or console programs and some Windows Forms applications.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 18:12 #17538

  • info@task.si's Avatar


  • Topic Author


  • Posts: 17
  • Hi Wolfgang !
    Thank you for this information. Till now I was not thinking in this way at all (without X# dll).
    As you probably notize I am a "half year" newbie in all technologies (Blazor, C#, HTML, CSS, X#, .NET, web) so it very difficult to understand all things.
    Did you try anything in Blazor ? I can show you and to others my first real app written in this new MS tool. Off course aprox. 40 % of code is in X#. X# and Blazor just opened me a total new world.

    Andrej

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 18:36 #17539

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2520
  • Hi Andrej,
    X# is basically a C# compiler that understands X# syntax and has many additions to make VO/VFP/XB++ also compile.
    The Core dialect does not knows the Xbase datatypes, and it was the first available dialect (I had the first small application in production after about a year of the first compiler release).
    Regarding Blazor: unfortunately I'm more than busy with my desktop applications, both in X# and in VO, and therefore I have no time for web applications. This is the area of my wife and another programmer in my company - they do all the web work with PHP, MySQL and PostgreSQL (and of course all the CSS and Javascript that is needed).
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 19:30 #17541

  • Frank Müßner's Avatar

  • Frank Müßner


  • Posts: 204
  • Hi Andrej,

    i would like to see the Blazor code. i Try to create a web program with Blazor/X#. :-)

    Regards Frank

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 22 Feb 2021 20:20 #17543

  • info@task.si's Avatar


  • Topic Author


  • Posts: 17
  • Hi Frank !

    Where to begin ?
    Bellow you will find my very first example. I made a simple note (for me):
    '

    In the razor page (fetchdata.razor) we refer to our X# DLL with:

    @using SMTP_XShCore_Lib


    @page "/fetchdata"
    @using System;
    @using System.Runtime.InteropServices;
    @* whatever you name your DLL or namespace*@
    @using SMTP_XShCore_Lib


    <h1>using X# code and Blazor</h1>


    <button class="btn btn-primary" @onclick="Test_XSharp">Start</button>


    @code {
    private void Test_XSharp()
    {
    // we are testing class Calculate which is defined in X# Core prg file; i.e. in //SMTP_XShCore_Lib.dll
    // note 5.2 and 7.3 are parameters - dimensions of rectangual's sides
    Calculate myCalculation = new Calculate(5.2, 7.3);
    double dAreaOFRectangual = myCalculation.dArea;
    //Console.WriteLine("The area of rectangual is {0}", dareaOFRectangual);

    }
    }

    We can instantiate Calculate class as shown above and assign a return value from our X# DLL
    Hope it helps for a beginning.
    I can send you also a screen grab of my almost final app (also on android). You can contact me :
    infoattask.si
    Andrej

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 26 Feb 2021 11:10 #17572

  • Horst's Avatar

  • Horst


  • Posts: 227
  • Hallo
    About Val in VO and XSharp

    NTrim(Val("21.02.2021") )
    XSharp = 21.02
    VO = 0

    Horst

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 26 Feb 2021 17:13 #17576

  • info@task.si's Avatar


  • Topic Author


  • Posts: 17
  • Hi Horst !
    I started with this topic, so I will also answer you if it is necessar at all. Why do you need to get numeric value from a string date ??

    According to X# Runtime Documentration:
    Val("26.02.2021") return correct value !!
    See bellow:
    If <cNumber> is a valid numeric expression, Val() processes it all. However, if <cNumber> is not entirely a valid numeric expression but does contain decimal numerics, Val() evaluates it until it reaches a second decimal point, the first non-numeric character, or the end of the expression. Leading spaces are always ignored. All variables containing a FLOAT type have internal picture information (like a template) relating to digits and decimals (see FloatFormat()).

    ---- end so on ...

    Best regards Andrej

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 26 Feb 2021 17:46 #17577

  • Chris's Avatar

  • Chris


  • Posts: 2346
  • Hi Andrej,

    In an ideal world, you would be absolutely right! But this topic of the help file is actually taken from the Visual Objects help file, and the current implementation of Val() is supposed to be 100% compatible with VO (we'll maybe need to provide a different version 100% compatible with VFP or other dialects in the future).

    But as it happens in 90% of the cases, the documentation of VO is slightly or very different to what really happens in VO! And the problem with that is that existing code might (and very often does) rely on such different behavior of the VO runtime compared to the documented behavior, so we need to in practice emulate the behavior, not the docs unfortunately. This has happened in literally 100s of places when trying to make the VO functions in X# really VO compatible..
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 26 Feb 2021 18:52 #17578

  • Chris's Avatar

  • Chris


  • Posts: 2346
  • Hi Horst,

    Horst wrote: About Val in VO and XSharp

    NTrim(Val("21.02.2021") )
    XSharp = 21.02
    VO = 0


    Thanks for the report, I see this as well. I did some more test in Visual Objects, see the results:

    SetDecimalSep(Asc("."))
    ? Val("21.02.2021")   // 0
    ? Val("21.02,2021")   // 21.02
    ? Val("21,02.2021")   // 21
    ? Val("21,0220.21")   // 21
    ? "---"
    SetDecimalSep(Asc(","))
    ? Val("21.02.2021")   // 0
    ? Val("21.02,2021")   // 0
    ? Val("21,02.2021")   // 0
    ? Val("21,0220.21")   // 21.0220

    We will try to replicate some of those cases in X#, but clearly we cannot fully replicate ALL this madness ;)

    Strangest thing is that this code

    SetDecimalSep(Asc(","))
    ? Val("12,3.0") // 0
    ? Val("12,34.0") // 0

    returns 0 in VO, but

    SetDecimalSep(Asc(","))
    ? Val("12,345.0") // 12,345

    returns 12,345 !!! Obviously we can not replicate this, but I am really wondering what the original code of the runtime in VO looks like to produce such kind of results..
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    _Val() function xsharp.core 27 Feb 2021 08:23 #17581

  • Horst's Avatar

  • Horst


  • Posts: 227
  • Hallo Andre and Chris

    A friend was using the val (x)=0 in a modul i had to translate to X#. He was using it in a IF construct.
    I already changed the code, so the prg will work like before.

    I wrote it here, so if somebody else was using that, he is warned.

    Horst

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 27 Feb 2021 09:53 #17582

  • Chris's Avatar

  • Chris


  • Posts: 2346
  • Understood Horst, and thanks for reporting! Will emulate some of this behavior in the runtime anyway.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 27 Feb 2021 10:39 #17583

  • Karl-Heinz's Avatar

  • Karl-Heinz


  • Posts: 595
  • Hi Chris,

    just found in the VO google group another Val() mystery. The VO Val() works with large scientific notations , but fails with small numbers. Playing with different SetDigit() / SetDecimals() settings makes no difference. Also, SetScience() seems to have no effect.

    groups.google.com/g/comp.lang.clipper.vi...bjects/c/Obd0ox-Hkhk

    i searched the VO group for "SetScience" but didn´t find another thread. It seems no one ever used scientific notations ? i tried the same code with X#, but it seems the X# Val() doesn´t support scientific notations yet.
    LOCAL x AS DWORD 
    
    SetDigit ( 20) 
    SetDecimal (15)
           
    ? x := Val ( AsString ( 4.95E+5 )) // 495000
    
    ? Val ( "4.95E+5" )   // 495000,000
    ? Val ( "4,95E+5" )   // 495000,000
    
    ? Val ( "4.95E-5" )   //  0,000 ?
    ? Val ( "4,95E-5" )   //  0,000 ?  
    		
    ? Val ( "-4.95E-5" )   //  -0,000 ?
    ? Val ( "-4,95E-5" )   //  -0,000 ? 		
    		
    SetScience ( TRUE ) 
    		
    ? x   // still shows 495000 , i would expect  4.95E+5  ?

    running this code with my FP-DOS shows the expected results
    SET DECIMAL to 10
    
    ? Val ( "4.95E+5" )   // 495000,0000000000
    ? Val ( "4.95E-5" )   // 0,0000495000
    ? Val ( "-4.95E-5" )   // -0,0000495000

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 27 Feb 2021 13:50 #17584

  • robert's Avatar

  • robert


  • Posts: 2074
  • Karl Heinz,

    There is a difference in VO between the value and the accuracy with which it is displayed:

    Instead of
    ? Val ( "4.95E-5" )   //  0,000 ?
    try this
    ? FloatFormat(Val ( "4.95E-5" ),20,15)   // 0.000049500000000
    As you can see Val() is calculating the correct value bot not using the SET DECIMAL setting for the resulting Float value.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    _Val() function xsharp.core 27 Feb 2021 18:29 #17586

  • Karl-Heinz's Avatar

  • Karl-Heinz


  • Posts: 595
  • Hi Robert

    thanks, FloatFormat() does the job.

    Using the SetScience(true) setting i tried Val ( "495000") and AsString(495000) to retrieve the scientific notation from a number. But no luck. What do you think how SetScience(true) was designed to work ?

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    • 2