Define a primitive data type: Difference between revisions
Content added Content deleted
(Omit Axe) |
No edit summary |
||
Line 1,786: | Line 1,786: | ||
End Structure</lang> |
End Structure</lang> |
||
=={{header|Visual FoxPro}}== |
|||
Visual FoxPro can't define primitives but they can be emulated with custom classes. |
|||
<lang vfp> |
|||
LOCAL o As BoundedInt |
|||
o = NEWOBJECT("BoundedInt") |
|||
DO WHILE NOT o.lHasError |
|||
o.nValue = o.nValue + 2 && will get as far as 9. |
|||
? o.nValue |
|||
ENDDO |
|||
DEFINE CLASS BoundedInt As Custom |
|||
nValue = 1 && default value |
|||
lHasError = .F. |
|||
PROCEDURE nValue_Assign(tnValue) |
|||
*!* This method will check the parameter and if |
|||
*!* it is out of bounds, the value will remain unchanged |
|||
*!* and an error generated. |
|||
tnValue = CAST(tnValue As I) |
|||
IF BETWEEN(tnValue, 1, 10) |
|||
THIS.nValue = tnValue |
|||
ELSE |
|||
ERROR "Value must be between 1 and 10." |
|||
ENDIF |
|||
ENDPROC |
|||
PROCEDURE Error(nError, cMethod, nLine) |
|||
IF nError = 1098 |
|||
MESSAGEBOX(MESSAGE(), 0, "Error") |
|||
ELSE |
|||
DODEFAULT() |
|||
ENDIF |
|||
THIS.lHasError = .T. |
|||
ENDDEFINE |
|||
</lang> |
|||
{{omit from|AWK}} |
{{omit from|AWK}} |
||
{{omit from|Axe}} |
{{omit from|Axe}} |