Advertisement
Guest User

IT 10 REVIEWER ANSWERS - PROCEDURES and ERROR HANDLING

a guest
Feb 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1.  
  2. 1. What is a procedure?
  3. > A procedure is a block of Visual Basic statements enclosed by a declaration statement and a matching End declaration. All executable statements in Visual Basic must be within some procedure.
  4.  
  5. 2. What are the different types of procedures?
  6. > The Sub procedure performs a task and then returns control to the calling code, but it does not return a value to the calling code.
  7. > The Function procedure performs a task and then returns control to the calling code. When it returns control, it also returns a value to the calling code.
  8.  
  9. 3. Write the syntax for the following:
  10. a. Sub Procedure
  11. ==========
  12. [Private/Public] Sub Subprocedure1(ByVal task As String)
  13. [sub statements to execute]
  14. End Sub
  15. ==========
  16.  
  17. b. Function Procedure
  18. ==========
  19. Function FunctionName [(ParameterList)] As ReturnType
  20. [function statements to execute]
  21. Return Value // this code is needed when you want your function to return a value
  22. End Function
  23. ==========
  24.  
  25. 4. What is the difference between Sub and Function procedures?
  26.  
  27. 5. How does a function procedure return a value?
  28.  
  29. 6. How do you invoke a Sub procedure?
  30. > Sub procedures can be executed only as a single statement in a VB.NET code.
  31. example: exampleSub()
  32. 7. How do you invoke a Function procedure?
  33. > Sub procedures can be executed only as a single statement in a VB.NET code.
  34. example: exampleSub()
  35. example 2: Dim testLength, testHypotenuse As Single
  36. testHypotenuse = hypotenuse(testLength, 10.7)
  37.  
  38. 8. What is an exception?
  39. > An exception is a response to an exceptional circumstance (in short: errors) that arises while a program is running, such as an attempt to divide by zero.
  40.  
  41. 9. Write the syntax of the Try…Catch… Statement.
  42. ==========
  43. Try
  44. [statements to execute]
  45. Dim strExampleCode = Example1.Text
  46. Catch ex As Exception
  47. [statements to execute when an exception/error is caught]
  48. MessageBox.Show(ex.ToString) // This code opens a message box containing the Exception as a string.
  49. Finally
  50. [statements to execute after the TRY CATCH] // statements will still whatever the outcome is
  51. End Try
  52. ==========
  53. NOTE: FINALLY Block is optional and you can end it all off with END TRY.
  54.  
  55. 10. Give an example of an exception.
  56. > Invalid Input - Mismatch on input values and variable types (ex. Typing a character where an integer is expected)
  57. > Stack Overflow - memory heap or variables reached their limits or something
  58. > Null Reference - Stuff/Values/Variables mentioned can't be found or does not exist
  59. > Division by Zero - enough said.
  60.  
  61. 11. How does a Try…Catch… statement work?
  62. > It "tries" to execute a set of statements and "catches" and exception or an error that occurred in the middle of the code execution.
  63.  
  64. 12. What is the function of the finally code block?
  65. > To execute a certain set of commands no matter what results/outputs come out from the TRY CATCH statement.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement