15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

592<br />

Creating Comments<br />

Creating Comments<br />

Visual Basic lets you create comment lines with the apostrophe (‘) or REM<br />

keyword, such as<br />

‘ The apostrophe defines a line comment<br />

PRINT “This is a simple BASIC program”<br />

REM The REM (Remark) keyword is another way<br />

REM to create a comment<br />

END ‘ This is the end of the program<br />

REALbasic uses both the apostrophe and the REM keyword along with the<br />

double slash characters (//), such as<br />

PRINT “This is a simple BASIC program”<br />

END // This is the end of the program<br />

Declaring Variables<br />

In early versions of BASIC, you could create a variable any time you needed<br />

it. However as BASIC adopted structured <strong>programming</strong> techniques, more<br />

modern dialects of BASIC (such as Visual Basic and REALbasic) now <strong>for</strong>ce<br />

programmers to declare variables by defining the variable name and data<br />

type. A typical variable declaration looks like this:<br />

Dim VariableName As DataType<br />

VariableName can be any descriptive name, such as SalesTax, Players_<br />

on_Team, or MoneyEmbezzled. The data type defines the type of data the<br />

variable can hold and the amount of data the variable can hold. You can also<br />

declare multiple variables on a single line, such as<br />

Dim VariableName1, VariableName2, VariableName3 As DataType<br />

Declaring string data types<br />

Strings represent text, such as a single character (“A”) or several words<br />

(“This is a string of text”). To declare a string variable, use the<br />

String keyword, such as<br />

Dim FirstName As String<br />

In Visual Basic (but not in REALbasic), you can also declare a variable as a<br />

Char data type, which can only hold a single character, such as the letter<br />

“H.” To declare a Char data type, use the Char keyword, such as<br />

Dim Grade As Char

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!