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:
Things to remember while writing code and looking for errors:
- Always initialize variables no matter what!!
- Try not to look for things that ‘aren’t needed’
- Strings can have numbers and always need “ “
VB is different from QB because …
VB includes visual and graphic interactive aspects while QB uses mainly sound and text and the only interactive feature is entering a text
four different types of controls in VB
label, textbox, command, image
method
A block of code associated with an object or event. AKA the code between “Private Function” and “End Sub”
Window
all our code
example of event
clicking a button (event handler say what happens when you for ex. click the button)
IDE
Integrated developing environment
MID
et ‘n’ characters starting on the ‘m’th character in a string. eg: print MID(string,m,n)
right
Get the rightmost ‘n’ characters in a string eg: print RIGHT(string,n)
left
Get the leftmost ‘n’ characters in a string eg: print LEFT (string,n)
UCASE
the word prints in upper case letters
eg: print UCASE(string)
LCASE
the word prints in lower case letters
eg: print LCASE(string)
STR
turns number into a string
eg. STR(number)
VAL
turns string to number
eg. VAL(“string”)
what are some early computer coding languages
Qbasic
COBAL
FORTRAN
Recent languages
Java
Visual Basic
C++
Q basic is _______ programing
interpretive
Uses for QB
Games,
Small simulations,
Math programs,
Programming contests.
Two reasons programs won’t work
Syntax errors (bad spelling) logic errors (bad instructions)
What is ‘debuging’?
finding and fixing problems in code.
t or f: print using function will round numbers
true.
eg. PRINT USING “$0.00” ; 9.999
will output as: $10.00
color code of black, white, red
00 - black
04 - red
15 - white
how do you centre a word?
find the length of the word + divide that number by two
and subtract it from 40.
Y= 40 - ( LEN(string) /2
in less than or equal to is the = sign before or after
after!