Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is an entry level Visual Basic program that I could really use help with fo

ID: 3691682 • Letter: T

Question

This is an entry level Visual Basic program that I could really use help with for basic functions. Please include comments in the code that you feel will help me learn these basic functions for future learning. I'm using Visual Studio 2010 and know to let it fill in code when it can, I just need the information that goes into the sub. I appreciate your help!!

Textboxes:

txtStartMileage
txtEndMileage
txtGallons

Labels:
lblMileage (Display of calculated mileage)
lblMessage (Display description of mileage from input in txtStartMileage, txtEndMileage, and txtGallons)

Buttons:

btnCalculate
btnClear
btnDefault
btnExit

Write an “if” statement that checks to see if the text properties for the textboxes txtStartMileage, txtEndMileage and txtGallons are blank. If they are blank, load an error message into label lblMessage’s text property stating that Start Mileage, End Mileage, and Gallons must be entered.
In an “else” clause to the above “if” clause, do the following in a code block:
o    Create an integer variable called intMileage and load it with value 0.
o    Move a blank string to the text property of lblMessage.
o    Calculate the mileage using the formula: (Mileage Ending – Mileage Starting) / Gallons.
o    The text properties of the textboxes must be converted to integer values by means of the ToInt32 method of the Convert object, like: Convert.ToInt32(txtEndMileage.Text)
o    Load the result into the integer variable intMileage.
o    The integer intMileage must be converted to a string and the result moved to the text property of the label lblMileage. Use the following syntax: intMileage.ToString().

The code for the Default Values button is listed below:
•    Convert the value 3000 to a string and move it to txtStartMileage.Text.
•    Convert the value 3200 to a string and move it to txtEndMileage.Text.
•    Convert the value 160 to a string and move it to txtGallons.Text.

The Clear button will clear the start mileage, end mileage & gallons text boxes

You can initialize the txtstart, txtend, txt gallons textboxes to values in a procedure file called: form_Load().
1.    Double click on the FORM and the Form_Load() procedure will appear.
2.    Use the following example to initialize the variables to:
•    Convert the value 3000 to a string and move it to txtStartMileage.Text.
•    Convert the value 3200 to a string and move it to txtEndMileage.Text.
•    Convert the value 160 to a string and move it to txtGallons.Text.

Explanation / Answer

txtStartMileage.Text=3000

txtEndMileage.Text=3200

txtGallons.Text=160

End Sub

If txtStartMileage.Text==" " Or txtEndMileage.Text==" " Or txtGallons.Text==" " then

lblMessage.text="   Start Mileage, End Mileage, and Gallons must be entered"

else

  intMileage As Integer = 0

lblMessage.text=" "

intMileage = (Convert.ToInt32(txtStartMileage.Text)- Convert.ToInt32(txtEndMileage.Text))/ Convert.ToInt32(txtGallons.Text)

lblMileage.Text=intMileage.ToString()

lblMessage.Text=" StartMileage :" + txtStartMileage.Text +"EndMileage:"+txtEndMileage.Text+"Gallons :"+txtGallons.Text

End IF

End Sub

lblMessage.Text=" "

txtStartMileage.Text=3000

txtEndMileage.Text=3200

txtGallons.Text=160

intMileage = (Convert.ToInt32(txtStartMileage.Text)- Convert.ToInt32(txtEndMileage.Text))/ Convert.ToInt32(txtGallons.Text)

lblMileage.Text=intMileage.ToString()

lblMessage.Text=" StartMileage :" + txtStartMileage.Text +"EndMileage:"+txtEndMileage.Text+"Gallons :"+txtGallons.Text

End Sub

txtStartMileage.Text=" "

txtEndMileage.Text=" "

txtGallons.Text=" "

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnExit.Click

Dim Response As Integer

MessageBox.Show("Do you really want to exit?", "", _

MessageBoxButtons.YesNo, MessageBoxIcon.Question)

If Response = vbYes Then

Me.Close()

End If

End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote