Thursday, February 27, 2014

Section 8.2 Text Files: StreamReaders, StreamWriters, and Structured Exception Handling




40011:  Assume that s is a string variable that is supposed to contain a value to be converted to integer.  Write a fragment of code that converts the value to integer variable and displays that value multiplied by 2.  If the value cannot be converted, display the message 'Invalid number' instead.

Try
MessageBox.Show(CInt(s) * 2)
Catch
MessageBox.Show("Invalid number")
End Try

4 comments:

  1. 40442: eurasiaSales = add(euroSales, asiaSales)
    40443: cubeVolume = toThePowerOf(cubeSide, 3)
    40804: sqrt((a*a)+(b*b))
    40458:
    Function twice(parameter1 As Integer)

    DIM result As Integer = parameter1 * 2
    return result

    End Function
    40459:
    Function add(parameter1 As Integer, parameter2 As Integer)
    DIM sum As Integer = parameter1 + parameter2
    return sum
    End Function

    ReplyDelete
  2. 40455: max(max(population1, population2), max(population3, population4))
    40801: sqrt(sqrt(x))

    ReplyDelete
  3. 40802: twice(twice(twice(x)))
    40803: oneMore(oneMore(oneMore(oneMore(x))))

    ReplyDelete