Page 2 of 3
_Val() function xsharp.core
Posted: Mon Feb 22, 2021 7:20 pm
by info@task.si
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
_Val() function xsharp.core
Posted: Fri Feb 26, 2021 10:10 am
by Horst
Hallo
About Val in VO and XSharp
NTrim(Val("21.02.2021") )
XSharp = 21.02
VO = 0
Horst
_Val() function xsharp.core
Posted: Fri Feb 26, 2021 4:13 pm
by info@task.si
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
_Val() function xsharp.core
Posted: Fri Feb 26, 2021 4:46 pm
by Chris
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..
_Val() function xsharp.core
Posted: Fri Feb 26, 2021 5:52 pm
by Chris
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:
Code: Select all
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
Code: Select all
SetDecimalSep(Asc(","))
? Val("12,3.0") // 0
? Val("12,34.0") // 0
returns 0 in VO, but
Code: Select all
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..
_Val() function xsharp.core
Posted: Sat Feb 27, 2021 7:23 am
by Horst
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
_Val() function xsharp.core
Posted: Sat Feb 27, 2021 8:53 am
by Chris
Understood Horst, and thanks for reporting! Will emulate some of this behavior in the runtime anyway.
_Val() function xsharp.core
Posted: Sat Feb 27, 2021 9:39 am
by Karl-Heinz
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.
https://groups.google.com/g/comp.lang.c ... bd0ox-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.
Code: Select all
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
Code: Select all
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
_Val() function xsharp.core
Posted: Sat Feb 27, 2021 12:50 pm
by robert
Karl Heinz,
There is a difference in VO between the value and the accuracy with which it is displayed:
Instead of
try this
Code: Select all
? 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
_Val() function xsharp.core
Posted: Sat Feb 27, 2021 5:29 pm
by Karl-Heinz
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