Question

In this exercise, you’ll add code to a form that converts the value the user enters based on the selected conversion type.

Conversions Conversion: Meters to feet Meters 500 Feet 1,640.40 Calculate Exit

The application should handle the following conversions:

1. Open the Conversions project. Display the code for the form, and notice the rectangular array whose rows contain the value to be displayed in the combo box, the text for the labels that identify the two text boxes, and the multiplier for the conversion as shown above. Note: An array is similar to a string with an index beginning with 0 (zero).

2. Set the DropDownStyle property of the combo box so the user must select an item from the list.

3. Add code to load the combo box with the first element in each row of the rectangular array, and display the first item in the combo box when the form is loaded.

4. Add code to change the labels for the text boxes, clear the calculated length, and move the focus to the entry text box when the user selects a different item from the combo box.

5. Test the application to be sure the conversions are displayed in the combo box, the first conversion is selected by default, and the labels change appropriately when a different conversion is selected.

6. Add code to calculate and display the converted length when the user clicks the Calculate button. To calculate the length, you can get the index for the selected conversion and then use that index to get the multiplier from the array. Test the application to be sure this works correctly.

7. Add code to check that the user enters a valid decimal value for the length. Then, test the application one more time to be sure the validation works correctly.

Here is the starting code:

Public Class Form1

Dim conversionTable(,) As String = {
{"Miles to kilometers", "Miles", "Kilometers", "1.6093"},
{"Kilometers to miles", "Kilometers", "Miles", "0.6214"},
{"Feet to meters", "Feet", "Meters", "0.3048"},
{"Meters to feet", "Meters", "Feet", "3.2808"},
{"Inches to centimeters", "Inches", "Centimeters", "2.54"},
{"Centimeters to inches", "Centimeters", "Inches", "0.3937"}}

Public Function IsPresent(ByVal textbox As TextBox, ByVal name As String) _
As Boolean
If textbox.Text = "" Then
MessageBox.Show(name & " is a required field.", "Entry Error")
textbox.Select()
Return False
Else
Return True
End If
End Function

Public Function IsDecimal(ByVal textbox As TextBox, ByVal name As String) _
As Boolean
Dim number As Decimal = 0
If Decimal.TryParse(textbox.Text, number) Then
Return True
Else
MessageBox.Show(name & " must be a decimal value.", "Entry Error")
textbox.Select()
textbox.SelectAll()
Return False
End If
End Function

Private Sub btnExit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

End Class


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Design coading:

Form1.vb Form1.vb [Design] x Form1 name: cmbconversion Conversion Textbox:txtfirstt Meters Textbox:txtsecond Feet Label name 1bllfirst Calculate Button name:btnexit an Button name:btncalculate Label name:lblsecond

Coding:

Public Class txtfirst
    Dim conversionTable(,) As String = {
    {"Miles to kilometers", "Miles", "Kilometers", "1.6093"},
    {"Kilometers to miles", "Kilometers", "Miles", "0.6214"},
    {"Feet to meters", "Feet", "Meters", "0.3048"},
    {"Meters to feet", "Meters", "Feet", "3.2808"},
    {"Inches to centimeters", "Inches", "Centimeters", "2.54"},
    {"Centimeters to inches", "Centimeters", "Inches", "0.3937"}}
    Dim i As Integer = 0

    Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
        Me.Close()
    End Sub

    Private Sub txtfirst_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Fill_combo()
    End Sub
    Public Function Fill_combo()
        For i As Integer = 0 To (conversionTable.GetUpperBound(0)) - 1
            cmbconversion.Items.Add(conversionTable.GetValue(i, 0))
        Next
    End Function

    Public Function IsPresent(ByVal textbox As TextBox, ByVal name As String) _
          As Boolean
        If textbox.Text = "" Then
            MessageBox.Show(name & " is a required field.", "Entry Error")
            textbox.Select()
            Return False
        Else
            Return True
        End If
    End Function
    Public Function IsDecimal(ByVal textbox As TextBox, ByVal name As String) _
           As Boolean
        Dim number As Decimal = 0
        If Decimal.TryParse(textbox.Text, number) Then
            Return True
        Else
            MessageBox.Show(name & " must be a decimal value.", "Entry Error")
            textbox.Select()
            textbox.SelectAll()
            Return False
        End If
    End Function

    Private Sub btncalculate_Click(sender As Object, e As EventArgs) Handles btncalculate.Click
        If (IsPresent(txtfirstt, txtfirstt.Text) = False) Then
        ElseIf (IsDecimal(txtfirstt, txtsecond.Text) = False) Then

        Else
            calculate(lbllfirst.Text, lblsecond.Text)
        End If

    End Sub

    Private Sub cmbconversion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbconversion.SelectedIndexChanged
        For i As Integer = 0 To (conversionTable.GetUpperBound(0)) - 1
            If (cmbconversion.Text = conversionTable.GetValue(i, 0)) Then
                lbllfirst.Text = conversionTable.GetValue(i, 1)
                lblsecond.Text = conversionTable.GetValue(i, 2)
            End If
        Next
    End Sub

    Private Sub calculate(first As String, second As String)
        For i As Integer = 0 To (conversionTable.GetUpperBound(0)) - 1
            If (first = conversionTable.GetValue(i, 1) And second = conversionTable.GetValue(i, 2)) Then
                txtsecond.Text = Val(txtfirstt.Text) * conversionTable.GetValue(i, 3)
            End If
        Next

    End Sub

End Class


output:

if you still have any dout regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........

Add a comment
Know the answer?
Add Answer to:
In this exercise, you’ll add code to a form that converts the value the user enters...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the valu...

    Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...

  • Design JavaFX application with 7 labels and one textfield where user enters input inches. When user...

    Design JavaFX application with 7 labels and one textfield where user enters input inches. When user enters his choice and presses enter key to complete input, program outputs resulting yards, feet, and inches. Use class P5 that extends Application with start method in it, and class P5Pane that extends GridPane. The only instance variables for P5Pane class are inputInches where user enters input inches, and three labels: outYards, outFeet, and outInches where program displays result of conversion. Use the following...

  • JavaScript (Please debug this code) When a user enters a string in the input box, the...

    JavaScript (Please debug this code) When a user enters a string in the input box, the program is designed to add the string to an array. When the array reaches a certain length, the program displays all the users' entries in a list on the page. When you finish debugging, the user's entry in the input box should be cleared each time the submit button is clicked. Additionally, after five strings are submitted, the entire list of submitted strings should...

  • 3.1 - In this exercise, you will see how to offer a user a selection among...

    3.1 - In this exercise, you will see how to offer a user a selection among multiple choices. You can place all choices into a combo box using the following code: /** File HelloViewer.java */ import javax.swing.JFrame; public class HelloViewer { public static void main(String[] args) { JFrame frame = new HelloFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("HelloViewer"); frame.setVisible(true); } } ---------------------------- /** File HelloFrame.java */ import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.BorderLayout; import java.awt.Font; public class HelloFrame extends JFrame { private String message; private...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  • C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to...

    C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to create a Windows Form Application that will mimics a calculator. This is the screenshot how it shouldl look like. Calculator It should have a textbox and the following buttons: + Addition - Subtraction * Multiplication / Division = Equals (Will perform the final calculation) C Clear (Will clear the text box) There will be no maximize or minimize buttons. The rules are these: 2...

  • Can someone modify my code so that I do not get this error: Exception in thread...

    Can someone modify my code so that I do not get this error: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1043) at java.awt.Container.add(Container.java:363) at RatePanel.<init>(RatePanel.java:64) at CurrencyConverter.main(CurrencyConverter.java:16) This code should get the amount of money in US dollars from user and then let them select which currency they are trying to convert to and then in the textfield print the amount //********************************************************************* //File name: RatePanel.java //Name: Brittany Hines //Purpose: Panel for a program that convers different currencyNamerencies to use dollars //*********************************************************************...

  • This is just part of a C# windows form Application. When the user enters their information, checks the check box to save info and hits the payment button the information is saved to a .txt file. When...

    This is just part of a C# windows form Application. When the user enters their information, checks the check box to save info and hits the payment button the information is saved to a .txt file. When user enters last name and clicks autofill if name is found in file it will auto fill the boxes but i'm having issues with this part. For some reason it skips the firstname box and enters the last name in the first name...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT