FoxPro data types

This is a very useful function!. It tells you the type of a variable. This causes instant laughter with a C-programmer: What? The program tells you the variable type? You must tell the program!

Yes! It is another world. Extremely flexible. In C you say:
int inumber = 60;
char pFuzzi[] = "a string for my program";
and if you assign anything to these variables which is not in accordance with their type, the compiler will shake it's head.

And now comes FoxPro® and allows you to assign a different type of information to a variable:
myvari = "lets start with a string"
myvari = 20
result = myvari + 100
if the second line was not there you will get an error since (not even) FoxPro® can add a number to a string. But including the second line, its fine.


And because it is possible, it makes sense to ask the program: what type of variable is myvar at the moment:
mytype = type("myvar")
and mytype will be "N" (=numeric) since it was set to 20

types are:

CCharacter, Varchar, Varchar (Binary)
NNumeric, Float, Double, or Integer
UUndefined type of expression or cannot evaluate expression.
..There are more (see Microsoft help)

There are more results for type() and an additional parameter for the function:"

Microsoft help: type(), vartype()

Let's come back to comparing C and FoxPro®. After writing C-source you start a program to check this source and generate an executable program. In this process, all variables are checked in the flow of the program and you will get errors as described above. During compilation, all variable names are exchanged by addresses and will not be needed to run the program. Adventage: high level of error detection.

FoxPro® also checks the source for errors but finds much less since there is no unique definition of variables. Some errors are not obvious before the line is executed.