xsharp.eu • Variable declarations.
Page 1 of 1

Variable declarations.

Posted: Fri Sep 27, 2019 11:45 am
by Anonymous
It looks like all variables have to be declared, for example:

Code: Select all

for x = 1 to 10
    ? x
next
... is fine in VFP as there's no static typing. In X# VFP the closest you can get would be this, right?

Code: Select all

for var x = 1 to 10
    ? x
next

Variable declarations.

Posted: Fri Sep 27, 2019 1:02 pm
by lumberjack
Hi Alan,
alanbourke wrote:It looks like all variables have to be declared, for example:

Code: Select all

for x = 1 to 10
    ? x
next
... is fine in VFP as there's no static typing. In X# VFP the closest you can get would be this, right?

Code: Select all

for var x = 1 to 10
    ? x
next
Or you can just use a typical XBase style declaration:

Code: Select all

local x
For x = 1 to 10
  ? x
endfor
// Alternatively
For Local x = 1 AS Int to 10

Variable declarations.

Posted: Fri Sep 27, 2019 2:52 pm
by robert
Alan,
If you enable 'Memvar' support and enable 'Undeclared memvar' support then this should work without any declarations, but I would not recommend that. It will produce code that is much less efficient
The least that you should do is declare them locally.
But it is much better to either declare the type yourself or use the VAR syntax and let the compiler determine the type.

Robert