Command Syntax

 <  Day Day Up  >  

When you first look at Visual Basic code, there are so many unrecognizable constructs that it's often difficult to tell what you're looking at. But they usually have equivalents in FoxPro.

For that reason, you should take a few minutes to go over Table 1.3 and familiarize yourself with some of the principal similarities and differences in command syntax.

Table 1.3. Command Syntax Differences

Item

Visual Basic

Visual FoxPro

Continuation character

_ ( underscore )

; (semicolon)

Comments

' (single quote)

* (asterisk) at the beginning of a line, && (two ampersands) anywhere else

Data type indicators

Deprecated in Visual Basic

{} (curly braces) around dates

Boolean literals

True False

.T. .F. or T F

String delimiters

""

"" , '' , []

Null

Nothing (the word)

.Null. or Null

Character literals

"abc"c

"abc"

Attributes of functions

<attr("value")>

No equivalent

Option Explicit On

Variables can't be used unless previously declared

No equivalent

Option Strict On

Narrowing conversions not allowed; default is Off

No equivalent

Option Compare Text

Case insensitivity

Must be explicit in FoxPro, for example, IF UPPER(a)=UPPER(b)...

Refer to class libraries

Imports (top of file)

SET CLASSLIB TO Name ADDITIVE or SET PROCEDURE TO Name ADDITIVE

Refer to base class

Inherits

ClassLibrary name shown in the Properties sheet, or declared with "as classname of sourcefilename " in code.

Namespace

Prefixes for classes

No equivalent

Array dimensioning

Dim X(2) is 3 long; X(0) is first one; all elements same type

Dim X(2) is 2 long; X(1) is first one; elements can be of different types

Array initialization

Can assign values, for example, Dim x(2) as new integer = {1,4}

DIMENSION X(2) or DECLARE X(2) , then assign individual cells ' values one line at a time

Parameters

Specified in Function or Sub statement in parentheses, with type declaration

Before Visual FoxPro7, specified in PARAMETERS or LPARAMETERS statement; beginning with Visual FoxPro7, same style as in Visual Basic .NET

Properties

Create property procedures with GET and SET methods , using a private variable as the get/set target; property name appears in Properties sheet of derived classes.

Enter the property name in the Class Designer, or assign a value to a variable name at the top of a class definition in code; the property appears immediately in the Properties sheet of the Class Designer

Default prefix block

WITH / ENDWITH

WITH / ENDWITH

Events

Used to call as yet unnamed functions in other modules

Don't have 'em, don't need 'em

Delegates

Var = AddressOf FunctionName; used to pass functions as parameters

Don't have 'em, don't need 'em

Determine variable type

TypeOf Var IS Typename or GetType()

TYPE() or VARTYPE()

Argument lists

Either positional or (Name:=Value)

Positional only

Variable or object creation

Dim VarName as Class ; VarName = New Class ; VarName = Value , or Dim VarName as New Class = Value

SET CLASSLIB TO XYZ ; VarName = CREATEOBJECT("Class") , or VarName = NEWOBJECT("Class", "Lib.VCX")

Object creation from a COM object

CreateObject("Word.Application")

CreateObject("Word.Application") or GetObject("Word.Application")

Cast operators

CTYPE()

Individual cast functions like DTOC() or STR()

Reference to container

ME

THIS , THISFORM

If statement syntax

IF Expr Then ; End If

IF Expr ; ENDIF

Case statements

Select Case VarName ; Case "abc" ; Case else ; End Select

DO CASE ; CASE Name="abc" ; OTHERWISE ; ENDCASE


This is not meant to be an exhaustive list; we'll save that for Appendix A at the end of the book, where you can find a concordance of Visual FoxPro and Visual Basic equivalents.

 <  Day Day Up  >  


Visual Fox Pro to Visual Basic.NET
Visual FoxPro to Visual Basic .NET
ISBN: 0672326493
EAN: 2147483647
Year: 2004
Pages: 130
Authors: Les Pinter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net