I need help with visual Basic studio 1 Passing by Value mean
I need help with visual Basic studio
1. Passing by Value means a copy is made of the parameter being passed and the sub-routine works on that copy.
True or False
2. Sub-routines may have zero, one, or more parameters (arguments) passed to them.
True or False
3. Passing by Reference means a copy is made of the parameter being passed and the sub-rountine works on that copy.
True or False
4. The ListBox Add method always uses no parameters.
True or False
5. Parameters are either passed by Reference or passed by Value.
True or False
6. The name of the parameter in the Sub Routine must match the name of the variable being passed to it.
True or False
Solution
1. Passing by Value means a copy is made of the parameter being passed and the sub-routine works on that copy.
Answer: True
Explanation: When a sub-routine takes a parameter, it means that we are passing a value for the parameter. When we are using Passing by Value it means that we are making a copy of the parameter and that copy is made available to the calling procedure, by using this means the operations being performed on the parameter does not affect the actual value. We use the keyword ByVal to pass a parameter by value
For example:
Private Sub Add(ByVal x As Integer)
x = x+5;
End Sub
In the above example the Add sub-routine takes x as parameter, if the value of x is 10, after the sub-routine is called, the value of x will be 15 inside the sub-routine only. The actual value of x remains unchanged.
2. Sub-routines may have zero, one, or more parameters (arguments) passed to them.
Answer: True
Explanation: A sub-routine may or may not have parameters. If parameters are passed there is no limit to it we can pass any number of parameters to a Sub-routine.
3. Passing by Reference means a copy is made of the parameter being passed and the sub-rountine works on that copy.
Answer: False
Explanation: Pass by reference is another way of passing parameters to a sub-routine. When a parameter is passed using Pass By reference the address of the argument is passed to the sub-routine, when pass by reference is used the parameter is accessed using the address passed to it. Using this technique the original value of the parameter is affected. We use ByRef keyword to pass a value by reference,
For example:
Private Sub Add(ByRef x As Integer)
x = x+5;
End Sub
In the above example the Add sub-routine takes x as parameter, here x takes the memory location of the parameter passed, if the memory location passed to x has a value 10, after the sub-routine is called, the value of x will be 15 both in and out the sub-routine. The actual value of x is changed, i.e., the value at the memory location passed to x is changed to 15.
4. The ListBox Add method always uses no parameters.
Answer: False
Explanation: The ListBox.Add method takes two parameters, one is the string to be added to the list which is mandatory and the second is the index, the index at which the item has to be added this is optional. Hence we can say that ListBox.Add method always has at least one parameter,
5. Parameters are either passed by Reference or passed by Value.
Answer: True
As discussed above the values are passed by using either the Pass By Value technique or by using Pass By Reference technique.
6. The name of the parameter in the Sub Routine must match the name of the variable being passed to it.
Answer: False
Explanation: The name of the parameter in the Sub Routine and the name of the variable being passed need not be the same, it is enough that both are of same datatype. That is the datatypes must match not the variable names. Variable name may be same or different.

