Presentation is loading. Please wait.

Presentation is loading. Please wait.

GCSE Computing:: Selection (IF statements)

Similar presentations


Presentation on theme: "GCSE Computing:: Selection (IF statements)"— Presentation transcript:

1 GCSE Computing:: Selection (IF statements)

2 Data Types: Why we need them
Data types are needed just as in databases so our program knows how to handle our variables; Getting the datatype right in first place is essential to reduce the amount of time finding errors (debugging) in your code; In Visual Basic 6.0 we can use the following datatypes: String (for storing letters, numbers and letters or words – e.g. “A4”, “September”, “N”) Integer (for storing small whole numbers between and – e.g. 1, 1000, 11000) Long (for storing large whole numbers between and ) Single (for small decimal numbers – e.g. 3.6 or 10.34) Double (for large decimal numbers – e,g, ) Date / Time (can be setup in different formats e.g. DDMMYY or DDMMYYYY) Boolean (holds only values of TRUE or FALSE – good for flags) Currency (similar to the Single datatype)

3 IF Statements: Why we need them
If statements allow us to ask the computer or user questions. Based on the answer of these questions we can take a particular route; Computers are only able to answer questions based on a 0 or 1, true or false, yes or no; If statements take the form of the following: Standard IF statements; IF, Else statements; IF, ElseIF statements; Nested IF statements.

4 IF Statements: In practice
The following code shows how we can use common IF statements: Dim sResponse as string sAnswer = Inputbox(“Does the plant have chlorophyll?”) If sAnswer = “No” then msgbox “This is not fungi” end if if sAnswer = “yes” then msgbox “This is fungi” End if

5 IF Statements: In practice
The following code shows how we can use IF Else statements: Dim sResponse as string sAnswer = Inputbox(“Does the plant have chlorophyll?”) If sAnswer = “No” then msgbox “This is not fungi” else msgbox “This is fungi” End if

6 IF Statements: In practice
The following code shows how we can use IF ElseIF statements: Dim sResponse as string sAnswer = Inputbox(“Does the plant have chlorophyll?”) If sAnswer = “No” then msgbox “This is not fungi” ElseIF sAnswer = “Yes” then msgbox “This is fungi” End if


Download ppt "GCSE Computing:: Selection (IF statements)"

Similar presentations


Ads by Google