Visual and Quick Basic Flashcards
How do we declare variables? Initialize?
the command DIM declares variables.
ex: DIM address AS STRING
initializing assigns data to a variable
ex: address = “156 Sunnyside Way”
ex: age = 15
What is a variable?
A variable is a place in computer memory where information is stored. They are called variables because they can change as the program is execute.
Why do we need variables
We need them because they store data for future use
ex: If the user is asked for their name, the computer should remember it
Two main facts about variables? (hint: relates to memory)
- we reserve memory for them
2. we give this memory a location name so we can refer to it later in our program
What are the 5 rules about declaring variables?
- No special characters (can contain only letters, numbers and periods)
- No spaces
- Cannot be over 40 characters long
- Cannot use command words (ex: print, input, etc.)
- Must begin with a letter
When do we use STRING?
when we want to use characters (they can have numbers in them too)
ex: DIM name as STRING
When do we use INTEGER?
when we want to use numbers without decimals (can be negative)
ex: DIM age AS INTEGER
When do we use SINGLE?
when we want to use a number that has decimals
ex: DIM weight AS SINGLE
What command do we use when we want the user to respond to a prompt?
INPUT “string”, variable
remember: use a comma to have no ‘?’ and a semi colon to have one
How do we use the random number function?
int (rnd * how many numbers in range + min num)
ex: range between 10 and 20 is
int(rnd * 11 + 10) NOT int(rnd * 20 + 10)
When would I use ‘PRINT USING’?
When you want to format how you print something.
ex: if I wanted 12.5 in price format ($12.50)
PRINT USING “$##.##”; 12.5
In Quick Basic, if I want to join a variable and a piece of text, I will do what..?
print “hello, “; name ; “. how are you?”
In Visual Basic, if I want to join a variable and a piece of text, I will do what..?
print “hello, “ & name & “. how are you?”
In Visual Basic, what is a ‘module’?
A block of code associated with an object or event. AKA the code between “Private Function” and “End Sub”.
In VB, what is a ‘property’?
An attribute or setting of an object. eg: Command1 has a default property of enabled = true.
In Visual basic, give an example of a property to modify in form, text box, image, label, and command.
form: caption text box: text image: picture label: caption caption: