Variable declarations.

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Anonymous

Variable declarations.

Post 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
User avatar
lumberjack
Posts: 729
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Variable declarations.

Post 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
______________________
Johan Nel
Boshof, South Africa
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Variable declarations.

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply