anonymous
2011-10-28 01:41:37 UTC
1) how many meters of carpet are needed (based on room dimensions)
2) how many rolls of carpet are required
3) how many meters of carpet are unused and left over
The program works fine however I want an error label to be displayed when a value lower than 5 or higher than 20 is entered in the width/length text boxes and the calculate button is clicked. I want the same error label to appear if a letter or symbol is entered in the width/length text boxes and the calculate button is clicked. What code would make this happen? Here’s my code so far:
Public Class Form1
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim width, length As Integer
If IsValidInput(txtWidth.Text) Then
width = txtWidth.Text
End If
If IsValidInput(txtLength.Text) Then
length = txtLength.Text
End If
CalculateAndDisplay(width, length)
End Sub
Sub CalculateAndDisplay(ByVal width, ByVal length)
Dim strips, totalLength, rolls, carpetLeft As Integer
Const rollwidth = 5
Const rollLength = 30
strips = width \ rollwidth
If width Mod 5 > 0 Then
strips = strips + 1
End If
totalLength = strips * length
rolls = totalLength \ rollLength
If CDbl(totalLength / rollLength) > CDbl(rolls) Then
rolls = rolls + 1
End If
carpetLeft = (rollLength * rolls) - totalLength
txtMetersRequired.Text = totalLength.ToString()
txtRollsRequired.Text = rolls.ToString()
txtWidthRemaining.Text = carpetLeft.ToString()
End Sub
End Class