_Val() function xsharp.core

This forum is meant for questions and discussions about the X# language and tools
info@task.si
Posts: 31
Joined: Mon Nov 02, 2015 2:08 pm

_Val() function xsharp.core

Post 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
User avatar
Horst
Posts: 336
Joined: Tue Oct 13, 2015 3:27 pm

_Val() function xsharp.core

Post by Horst »

Hallo
About Val in VO and XSharp

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

Horst
info@task.si
Posts: 31
Joined: Mon Nov 02, 2015 2:08 pm

_Val() function xsharp.core

Post 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
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

_Val() function xsharp.core

Post 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..
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

_Val() function xsharp.core

Post 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..
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Horst
Posts: 336
Joined: Tue Oct 13, 2015 3:27 pm

_Val() function xsharp.core

Post 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
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

_Val() function xsharp.core

Post by Chris »

Understood Horst, and thanks for reporting! Will emulate some of this behavior in the runtime anyway.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

_Val() function xsharp.core

Post 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
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

_Val() function xsharp.core

Post by robert »

Karl Heinz,

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

Instead of

Code: Select all

? Val ( "4.95E-5" )   //  0,000 ?
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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

_Val() function xsharp.core

Post 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
Post Reply