Your science teacher has asked you to create an application
Your science teacher has asked you to create an application that displays how much
a person would weigh on the following planets: Venus, Mars, and Jupiter. The
application’s
interface should allow the user to enter the person’s weight on Earth.
a. Perform the steps involved in creating an OO application. (See the Note at the
beginning of the Exercises section.) Include a button for clearing the screen.
b. Create an application, using the following names for the solution and project,
respectively: Planet Solution and Planet Project. Save the application in the
VB2015\\Chap02 folder. Change the form file’s name to Main Form.vb. Change
the form’s name to frmMain. Code the application using the Val and Format
functions. One pound on Earth is equal to 0.91, 0.38, and 2.53 pounds on Venus,
Mars, and Jupiter, respectively. Add appropriate comments in the General
Declarations section and in the coded procedures. Test the application using both
valid and invalid data.
Solution
Dim message, title, defaultValue As String
Dim myValue As Object
\' Set prompt.
message = \"Enter weight on earth\"
\' Set title.
title = \"Weights on planets\"
defaultValue = \"10\" \' Set default value.
weightOnEarth = InputBox(message, title, defaultValue)
Private Sub clearButton_Click() Handles clearButton.Click
\' Clear the weight.
weightOnEarth.setText(\"\");
End Sub
Private Sub cmdLogin_Click()
Double earth = weightOnEarth.getText();
Double venus = earth*0.91;
Double mars = 0.38 * earth;
Double Jupiter = 2.53*earth;
ResultTxt.setText(\"Venus: \"+venus+\" Mars: \"+mars+\" Jupiter: \"+Jupiter);
End Sub
