Following copied and referenced command values

A test controller uses the following Visual Basic program to update a force command. All numeric command and increment values represent newtons. In the first call, the same caller variable appears in both argument positions.


Visual Basic
Module Controller
    Sub UpdateCommand(ByRef stored As Double,
                      ByVal increment As Double)
        stored = stored + 0.5
        increment = increment * 2.0
        stored = stored + increment
    End Sub

    Sub Main()
        Dim command As Double = 3.0
        UpdateCommand(command, command)
        Dim afterFirst As Double = command

        UpdateCommand(command, 1.0)
        Dim afterSecond As Double = command
    End Sub
End Module


A flowchart shows two update calls with a saved value after each call.


Find the values stored in afterFirst and afterSecond when Main finishes. Give each answer in N, to one decimal place.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Visual Basic Questions: