Tracing overlapping mode ranges

A test program converts a sensor voltage into a force using a mode-dependent gain. Its Visual Basic function contains a selection block, which chooses a branch using the value of mode. The function is declared inside a module.


Visual Basic
Function GainFor(ByVal mode As Integer) As Double
    Select Case mode
        Case 1 To 3
            Return 1.5
        Case 3 To 5
            Return 2.0
        Case Else
            Return 0.0
    End Select
End Function


For each independent test below, the program obtains the gain from GainFor(mode) and calculates force from:


F=GVF = GV


Here GG is gain in N/V and VV is voltage in V. Complete the table with the gain actually returned and the calculated force. Enter exact integers or short decimals without units. Trace the code as written, including its overlapping ranges.

TestModeVoltage (V)Gain (N/V)Force (N)
Bench A22.0
Bench B34.0
Bench C41.5
Bench D62.5

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: