Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. What is a procedure?
- > 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.
- 2. What are the different types of procedures?
- > 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.
- > 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.
- 3. Write the syntax for the following:
- a. Sub Procedure
- ==========
- [Private/Public] Sub Subprocedure1(ByVal task As String)
- [sub statements to execute]
- End Sub
- ==========
- b. Function Procedure
- ==========
- Function FunctionName [(ParameterList)] As ReturnType
- [function statements to execute]
- Return Value // this code is needed when you want your function to return a value
- End Function
- ==========
- 4. What is the difference between Sub and Function procedures?
- 5. How does a function procedure return a value?
- 6. How do you invoke a Sub procedure?
- > Sub procedures can be executed only as a single statement in a VB.NET code.
- example: exampleSub()
- 7. How do you invoke a Function procedure?
- > Sub procedures can be executed only as a single statement in a VB.NET code.
- example: exampleSub()
- example 2: Dim testLength, testHypotenuse As Single
- testHypotenuse = hypotenuse(testLength, 10.7)
- 8. What is an exception?
- > 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.
- 9. Write the syntax of the Try…Catch… Statement.
- ==========
- Try
- [statements to execute]
- Dim strExampleCode = Example1.Text
- Catch ex As Exception
- [statements to execute when an exception/error is caught]
- MessageBox.Show(ex.ToString) // This code opens a message box containing the Exception as a string.
- Finally
- [statements to execute after the TRY CATCH] // statements will still whatever the outcome is
- End Try
- ==========
- NOTE: FINALLY Block is optional and you can end it all off with END TRY.
- 10. Give an example of an exception.
- > Invalid Input - Mismatch on input values and variable types (ex. Typing a character where an integer is expected)
- > Stack Overflow - memory heap or variables reached their limits or something
- > Null Reference - Stuff/Values/Variables mentioned can't be found or does not exist
- > Division by Zero - enough said.
- 11. How does a Try…Catch… statement work?
- > It "tries" to execute a set of statements and "catches" and exception or an error that occurred in the middle of the code execution.
- 12. What is the function of the finally code block?
- > 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