Miscellaneous questions about converting VO code to X#

This forum is meant for questions and discussions about the X# language and tools
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Hi Chris,

The single line will indeed make it easier.

Short question: what does #NULL_NUMBER mean in VO? I have about 20 occurrences and in VO it shows light grey without a tooltip or anything. Also I can't find it in the VO help or the Vo2Ado help. In X# it is not recognised but what should I use to replace it? Perhaps 0 (zero) or just NULL?

Kees.
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Re: Miscellaneous questions about converting VO code to X#

Post by ic2 »

Hi Kees,

Isn't it defined somewhere in the program?
If you open the MEF Standard library of VO's System library, you'll find:

Code: Select all

DEFINE NULL_CODEBLOCK   := CODEBLOCK(_CAST, 0L)
DEFINE NULL_DATE        := DATE(_CAST, 0L)
DEFINE NULL_PTR         := PTR(_CAST, 0L)
DEFINE NULL_ARRAY       := ARRAY(_CAST, 0L)  // ARRAY() -> ARRAYNEW()
DEFINE NULL_OBJECT      := OBJECT(_CAST, 0L)
DEFINE NULL_STRING      := STRING(_CAST, 0L) // ""
DEFINE NULL_PSZ         := PSZ(_CAST, 0L)
DEFINE NULL_SYMBOL      := SYMBOL(_CAST, 0)
But no NULL_NUMBER

Dick
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Kees,

What do you mean by "it is not recognized"? Does the compiler complain about it? Everything that starts with # is a symbol, so I assume it's just a symbol with a special meaning that you have created in your code.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Some more information about the #NULL_NUMBER. In VO there is, for example, the documented value NULL_DATE. This is sometimes used in the VO application as the symbol #NULL_DATE, mostly when the code is related to an SQL query. Likewise #NULL_NUMBER is used, mostly when it is part of an SQL query. But I can't find anywhere what it means, not in the VO, Vo2Ado or Xs2Ado documentation and not even in general on the internet. It is often used in an IIF() and there it causes problems in X#. For example, the expression

Code: Select all

IIF(cString = "abc", #NULL_NUMBER, nLongInt)
which is apparently fine in VO, results in error XS0173 "Type of IIF expression cannot be determined because there is no implicit conversion between 'symbol' and 'int'" in X#.

Kees.
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Kees,

NULL_DATE and #NULL_DATE are two totally different things. NULL_DATE is a constant defined in the runtime (both in VO and X#) and means an empty date value, while #NULL_DATE is a regular SYMBOL (a VO data type), which is defined nowhere in the runtime and has no special meaning by itself, it's just a symbol defined in your own code and is used to mean something in the context of your code only. It's no different to #ANYTHINGELSE or #ABC, #MYSYMBOL etc. Same goes for #NULL_NUMBER, it's a symbol you define and use in the app code and means something that depends only on what you are doing with it. It's no different really than using a string literal instead, like "NULL_NUMBER".

The compiler error that you are getting is because in .Net by default both result arguments of an iif() are supposed to be of the same data type, but in your code, the first one is a SYMBOL while the second one is an INT. But it's easy to change this behavior and make it VO-compatible, just please go to the project settings, Dialect page and check the option "Compatible IIF behavior". This will allow the code to compile without errors.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Hi Chris,

Thank you again. The thing is, I can't find where #NULL_NUMBER and #NULL_DATE are defined. They are just used without being defined anywhere. Is that possible? If they should be defined somewhere, how can I find it apart from using the standard VO search option which found nothing. I think I will change the project setting to eliminate these errors but I still wonder where these symbols came from. To be clear: I did not write the original VO application but my task is to move it to X#.

Kees.
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Kees,

SYMBOLs do not need to be declared anywhere, they can just be used as literals anywhere in the code. For example this is perfectly valid code:

Code: Select all

FUNCTION Start() AS VOID
	LOCAL s AS SYMBOL
	s := #TEST
	IF s == #SOMETHINGELSE
		? "something else"
	ELSEIF s == #TEST
		? "test"
	ENDIF
The symbol #SOMETHINGELSE is not defined or assigned anywhere in the code, but it's still a valid symbol.

It would had been the same if a STRING var was used instead:

Code: Select all

FUNCTION Start() AS VOID
	LOCAL s AS STRING
	s := "TEST"
	IF s == "SOMETHINGELSE"
		? "something else"
	ELSEIF s == "TEST"
		? "test"
	ENDIF
It's just that SYMBOLs are more convenient to use for things like that, as they are case insensitive and have a much smaller memory footprint than strings.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Hi Chris,

So I decided to leave the #NULL_DATE and #NULL_NUMBER symbols in the code, but now X# has a problem with #NULL_DATE. I get error XS9002 Parser: unexpected input '#' probably because NULL_DATE is seen as a constant and X# does not understand the # in front of it. Is there a way to use #NULL_DATE as a symbol?

Kees.
User avatar
Kees Bouw
Posts: 121
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Found it, it is probably String2Symbol("#NULL_DATE") right?
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Kees,

Yes, String2Symbol() is a good workaround, but I think the compiler error with #NULL_DATE is a bug, will open a report about it, thanks!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply