CSC312 advanced programming in VB For program execution we need to know how a computer works ! INPUT PROCESS OUTPUT 1- I (Input data) 2- Memorize,Analyze and process data 3- O (Output Data ) Data for computer : Image, sound, characters CPU may Input from Keyboard, file, the web, Microphone, camera, scanner.... Pure input (I)(read) devices : Kb(characters),Mic(sound), camera(image), scanner(image), mouse(choose).. CPU may output to Screen, printer, speaker, file, internet…. Pure Output (O) devices: Printer, screen, speaker INPUT
Input and output devices I/O 2 kinds : Communication devices: Bluetooth, Network Card,USB,IR Storage devices: Hard Disk, USB Flash Ram, CD, DVD Anlyze and process, how ? The computer uses 1- a memory called RAM, we store in RAM the constants and the variables (numeric or String) to solve a problem. 2- a CPU to do: - arithmetic operations +, -, *,^ - Logical operations <, >, =, <=,>=,<>,And Or Not - performs commands IF and GOTO A small calculator and a huge computer can do only those operations (They have nearly the same hardware). The difference between a small and a huge, are the programs (Software) that are saved in this computer. Square root, sine, cosine, word, excel, VB, play chess …..
Precedence for operators Arithmetic operators are : + - * / ^ Logical operators are: < > = <= >= <> AND OR NOT Precedence over operators 1- from left to right 2- inside parentheses ( ) 3- ^ 4- not & - unary operatorS (inverse) with one op. 5- * / 6- + - 7- = < > <= >= <> 8 - AND 9 - OR e.g. 2+2*3<4 or 3*(3+2)>12 = TRUE
AND OR NOT NOT is a unary operation it needs one operand, NOT(true) = False , NOT(False)= True e.G NOT(3<4) => False because 3<4 is True AND and OR need at least 2 operands, AND( a,b,c,d ) is True only if a and b and…Are True AND( a,b,c,d ) is False if a or b or c… is False e.g. 2<4 AND 3<5 AND 6<8 => True OR( a,b,c,d ) is True if a or b or c or d is True OR( a,b,c,d ) is False only if a and b and c and d are false. E.g. 2<3 OR 5<3 OR 7<2 => True
Variables We have mainly two kinds of data 1- Numeric 2- String (or Text) or alphanumeric A,B,…1,2,3. -A constant may be anything 12 or 1.4 or “TONI” -A variable (or Field) may contain any constant . - A variable name must start by an alphabetic char. and may contain numeric and underscore characters. It may not contain spaces. A12 valid. A 12 is not valid A_12B is valid Assignment A12=“Toni” means put Toni into A12 It is preferable in programming to give a name that has a meaning to a variable, e.g. Width for the width. M ore kinds a- boolean that may have the values TRUE or FALSE only. TRUE is internally : -1 and false is any other value(2 bytes). b- Date variable, is a string of 8 bytes exp : #2/22/1989#
Operations on variables You may assign a ny constant to a variable e.g. Temperature=1.2 so Temperature is a numeric variable Name=“Toni” so Name is a String variable Toni is a variable ,“Toni” is a string. You must put brackets for constants. YN=“12” XN is a string var. XN=12=> XN= num. Var. We may do arithmetic operations on numeric If you do arithmetic operations on string you will receive an error. XN=XN+1 correct, we assign XN+1 to XN =>13 YN=YN+1 => error because YN is a string variable “12”
EXERCISE To bring with you on a sheet of paper on next class The Mac Address of your mobile phone The Mac addresses of your notebook