Error Identification for Exam 2 Answer Key

advertisement
Imports System.Convert
Public Class frmMain
'Declare Constants for costs
Public Const fuelcost As Double = 2.65
Public Const carcost As Double = 49.99
Public Const insurancecost As Double = 14.99 “it needs to be declared as a double or
decimal
Public string1 As String
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnExit.Click
Me.Close()
End Sub
Private Sub lblReset_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblReset.Click
Call resetlabel(lblDaysRented)
Call resetlabel(lblUnitCostCar)
Call resetlabel(lblUnitCostInsurance)
Call resetlabel(lblUnitCostFuel)
Call resetlabel(lblExtendedCostCar)
Call resetlabel(lblExtendedCostInsurance)
Call resetlabel(lblExtendedCostFuel)
Call resetlabel(lblTotal)
Call resettext(txtFuelGallons)
txtFuelGallons.Focus()
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalculate.Click
Dim daysrented, fuel As Integer
Dim fueltotal, insurancetotal, cartotal, totalcost As Double
Dim dtpDateRented, dtpDateReturned As DateTime needs to be declared as dateTime
If Module1.dayvalidation(TextBox1.Text, TextBox2.Text, TextBox3.Text) = True And
Module1.dayvalidation(TextBox4.Text, TextBox5.Text, TextBox6.Text) = True Then error are
only passing two arguments to this procedure. The procedure requires three arguments.
dtpDateRented = Microsoft.VisualBasic.DateSerial(ToInt32(TextBox1.Text),
ToInt32(TextBox2.Text), ToInt32(TextBox3.Text))
dtpDateReturned = Microsoft.VisualBasic.DateSerial(ToInt32(TextBox4.Text),
ToInt32(TextBox5.Text), ToInt32(TextBox6.Text))
End If
daysrented = days(dtpDateRented, dtpDateReturned) dtptime is not Needed
fuel = ToInt32(txtFuelGallons.Text)
lblDaysRented.Text = System.Convert.ToString(daysrented)
lblUnitCostCar.Text = carcost.ToString("C")
If RadioButton1.Checked Then
lblUnitCostCar.Text = (carcost * 1.1).ToString("C")
cartotal = car(daysrented * 1.1)
ElseIf RadioButton3.Checked Then This needs to be an elseIf Statement. Otherwise
Its missing an EndIf and it will messes up the logic of the code.
lblUnitCostCar.Text = (carcost * 0.9).ToString("C")
cartotal = car(daysrented * 0.9)
Else
lblUnitCostCar.Text = (carcost).ToString("C")
cartotal = car(daysrented)
End If
lblUnitCostFuel.Text = fuelcost.ToString("C")
If CheckBox1.Checked Then equal doesn’t need to be here and you decide to put it
here, you must say = “true” or = “false”
lblUnitCostInsurance.Text = "0" missing quotes
insurancetotal = 0
Else
lblUnitCostInsurance.Text = insurancecost.ToString("C")
insurancetotal = insurance(daysrented)
End If
fueltotal = fuel1(fuel)
totalcost = total(fueltotal, insurancetotal, cartotal)
lblExtendedCostCar.Text = cartotal.ToString("C")
lblExtendedCostInsurance.Text = insurancetotal.ToString("C")
lblExtendedCostFuel.Text = fueltotal.ToString("C")
lblTotal.Text = totalcost.ToString("C")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
lblTime.Text = System.DateTime.Now.ToLongTimeString
End Sub
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll Needs to say .scroll and
not.clicked
txtFuelGallons.Text = HScrollBar1.Value.ToString
End Sub
Public Function days(ByVal dtpargdate1 As DateTime, _
ByVal dtpargdate2 As DateTime) As Integer
Return DateDiff(DateInterval.Day, dtpargdate1, dtpargdate2) needs to say
“return” not yield. Needs to say “DateDiff” not DateDiffernce. Needs to say “Day” not
“month”
End Function
Public Function fuel1(ByVal arg As Double) As Double
Return arg * fuelcost
End Function
Public Function insurance(ByVal arg As Double) As Double
Return arg * insurancecost
End Function
Public Function car(ByVal arg As Double) As Double
Return arg * carcost
End Function
Public Function total(ByVal fuel As Double, ByVal insurance As Double, ByVal car As
Double)
Return fuel + insurance + car
End Function
Public Sub resetlabel(ByVal lblarg As Label)
lblarg.Text = ""
End Sub
Public Sub resettext(ByVal txtarg As TextBox)
txtarg.Text = ""
End Sub
End Class
Module 1
Module Module1
Public
As String)
access and
If
Function dayvalidation(ByVal year As String, ByVal month As String, ByVal day
As integer “error needs to be declared as public or friend to be able to
it needs to be a Boolean value since you are returning true false statements
month >= 1 And month <= 12 Then
Select Case month need to say “Month” not “day” This is asking for days.
Logic error
Case 1, 3, 5, 7, 8, 10, 12
If day >= 1 And day <= 31 Then
Return True
Else
MessageBox.Show("Invalid day", "error",
MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
End If
Case 4, 6, 9, 11 Syntax error. Select Case Statements do not have If
before them.
If day >= 1 And day <= 30 Then
Return True
Else
MessageBox.Show("Invalid day", "error",
MessageBoxButtons.OKCancel, MessageBoxIcon.Error) “The messageboxButtons.OkCancel should
come after MessageBoxIcon.Error
End If
Case 2
If DateTime.IsLeapYear(year) = True Then
If day >= 1 And day <= 29 Then
Return True
Else
MessageBox.Show("Invalid day", "error",
MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
End If
Else
If day >= 1 And day <= 28 Then
Return True
Else
MessageBox.Show("Invalid day", "error",
MessageBoxButtons.OKCancel, MessageBoxIcon.Error) should be messagebox.show not .display
End If
End If
End Select
End If
End Function
End Module Missing End Module
Download