I'll be more specific in these examples:
Subroutines (& Functions)
You must state the names of the subroutines and what specific module they are in
You must mention any parameters that a subroutine uses, explain why they are a certain type and what they are used for in the subroutine.
'This subroutine requires a parameter value
'of type string which is referred to using the name data
'this value is processed by the subroutine
Public Sub ReactToInput(data As String)
End Sub
'of type string which is referred to using the name data
'this value is processed by the subroutine
Public Sub ReactToInput(data As String)
End Sub
Functions are subroutines that return a value, you need to explain what information is returned and what type it is.
You need to explain where the return value of a function is used, whether it is stored in a variable or whether it is used directly as part of some calculation or string manipulation.
'function returns an integer value back to the caller
Function GenerateNumber() As Integer
' do some code
Return 45
End Function
Function GenerateNumber() As Integer
' do some code
Return 45
End Function
'call the GenerateNumber subroutine and store
'the return value in the variable saveMe
saveMe = GenerateNumber()
'the return value in the variable saveMe
saveMe = GenerateNumber()
'combine the text with the return value from the function GenerateNumber
s = "I generated " & GenerateNumber() & " for you"
s = "I generated " & GenerateNumber() & " for you"
String manipulation
You should remember that & joins text together in visual basic
SubString(), ToLower() are both examples of string manipulation and you should describe how they work and how they are used.
Selection
You need to explain the test being performed for the IF and what code runs when the condition is true and what code runs when the condition is false.
If saveMe < 105 Then
'code if condition is true (saveMe is less than 105)
Else
'code if condition is false (saveMe is 105 or more)
End If
'code if condition is true (saveMe is less than 105)
Else
'code if condition is false (saveMe is 105 or more)
End If
Make sure you explain nested if structures carefully, highlighting the chain of tests that get you to certain parts of the nesting.
If saveMe > 0 Then
'code if condition is true (saveMe is greater than 0)
Else
'saveMe is not greater than 0
If saveMe = 0 Then
'code if condition is true (saveMe is 0)
Else
'saveMe must be less than 0 (not greater than or equal to 0)
End If
End If
'code if condition is true (saveMe is greater than 0)
Else
'saveMe is not greater than 0
If saveMe = 0 Then
'code if condition is true (saveMe is 0)
Else
'saveMe must be less than 0 (not greater than or equal to 0)
End If
End If
With select case, you need to explain what value is being tested for a match and then explain each of the possible matches and the code that is executed when each match is found.
'examine lowercase version of choice
Select Case choice.ToLower()
Case "open"
'code if choice is open
Case "close"
'code if choice is close
Case "delete"
'code if choice is delete
End Select
Select Case choice.ToLower()
Case "open"
'code if choice is open
Case "close"
'code if choice is close
Case "delete"
'code if choice is delete
End Select
Iteration (Loops)
In for loops you need to state the loop variable, it's starting value and its stop value (the value it will have during the last run of the loop).
'loop variable called clock starts at 1
'increases each time by 1, stops at 12
For clock = 1 To 12
Next
'increases each time by 1, stops at 12
For clock = 1 To 12
Next
You need to explain how the loop variable is used inside the loop, whether it is just a counter or whether it's value is used to perform some other task like accessing an individual character in a string.
For count = 1 To 10
'add current value of count to the total so far
total = total + count
Next
'add current value of count to the total so far
total = total + count
Next
In While loops make sure you explain the general purpose of the loop what does it do. You need to explain the condition that is tested at the start of the loop, explaining that the loop only keeps working if this condition is true. Make sure you explain where the end of the loop is and that the code jumps back to the start of the loop to test the condition at the end of each run through.
total = 45
'loop happens if total is less than 100
Do While (total < 100)
'add 7 to the total
'this will eventually cause loop to stop
total = total + 7
'end of loop must go back to Do While to test condition again
Loop
'loop happens if total is less than 100
Do While (total < 100)
'add 7 to the total
'this will eventually cause loop to stop
total = total + 7
'end of loop must go back to Do While to test condition again
Loop
No comments:
Post a Comment