I just started taking a VB class and I'm having an issue with the latest assignment. I'm supposed to design a program that calculates the cost, number of men and total time it will take to mow a lawn based on the size of the lawn. No problem.
The problem I'm having is that somehow my cost is rounding up to the tenths. If someone could take a look and let me know how to remedy this, I'd be eternally gratefull!!
Public Class frmLAB4 'Written By: J Wilbarger 'Declared variables for time formatting Dim intHours, intMin, intSec, intStart As Integer Dim dblYard, dblCostA, dblCostB As Double Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load End Sub Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click 'variable represents size of the yard dblYard = txtYard.Text 'Declaring cost values for variables based on the size of the yard. 'dblCostA = 3 cents/sf and dblCostB = 2.5 cents/sf dblCostA = (10 + (dblYard * 0.03)) dblCostB = (20 + (dblYard * 0.025)) If dblYard < 0 Then txtWorkers.Text = "Error" txtTime.Text = "Error" txtCost.Text = "Error" ElseIf dblYard <= 500 Then txtWorkers.Text = "1 Man" txtTime.Text = "00:25:00" txtCost.Text = "25.00" ElseIf dblYard > 500 Then txtWorkers.Text = "2 men" txtTime.Text = (300 + (dblYard * 2.4)) txtCost.Text = Format(dblCostA, 2) 'The following txtCost.Text output rounds up from.25 to .30...Why? ElseIf dblYard > 2000 Then txtWorkers.Text = "3 men" txtTime.Text = (3600 + (dblYard * 0.8)) txtCost.Text = Format(dblCostB, 2) End If 'Time formatting intStart = txtTime.Text intHours = intStart / 3600 intStart = intStart - (intHours * 3600) intMin = intStart / 60 intSec = Int(intStart - (intMin * 60)) txtTime.Text = intHours & ":" & intMin & ":" & intSec End Sub Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click txtYard.Text = Nothing txtWorkers.Text = Nothing txtTime.Text = Nothing txtCost.Text = Nothing End Sub Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click Close() End Sub Private Sub btnPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnPrint.Click PrintForm1.Print() End Sub End Class
Thanks in advance,