Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim length, iwidth, a, b, totallength, totalrolls, remainder As Integer
- Private Sub cmdCalculate_Click()
- 'resets length and width variables
- length = 0
- iwidth = 0
- 'retrieves length and width from the textboxes
- length = Val(txtlength.Text)
- iwidth = Val(txtwidth.Text)
- 'tests that length and width are numbers
- If Not IsNumeric(txtlength.Text) Then
- MsgBox ("You must enter a number for the length.")
- txtlength.Text = ""
- txtlength.SetFocus
- End If
- If Not IsNumeric(txtwidth.Text) Then
- MsgBox ("You must enter a number for the width.")
- txtwidth.Text = ""
- txtwidth.SetFocus
- End If
- 'tests that length and width are within 1 and 20 metres
- If IsNumeric(txtlength.Text) Then
- If length < 1 Or length > 20 Then
- MsgBox ("You must enter a length between 1 and 20")
- txtlength.Text = ""
- length = 0
- iwidth = 0
- txtlength.SetFocus
- End If
- End If
- If IsNumeric(txtwidth.Text) Then
- If iwidth < 1 Or iwidth > 20 Then
- MsgBox ("You must enter a width between 1 and 20")
- txtwidth.Text = ""
- txtwidth.SetFocus
- length = 0
- iwidth = 0
- End If
- End If
- 'calculates total length of carpet needed
- a = iwidth \ 5
- If iwidth Mod 5 > 0 Then
- a = a + 1
- End If
- totallength = a * length
- lbltotallength.Caption = Str(totallength) + " metres"
- 'calculates total rolls needed
- b = (a * length)
- totalrolls = b \ 30
- If b Mod 30 > 0 Then
- totalrolls = totalrolls + 1
- End If
- lbltotalrolls.Caption = totalrolls
- 'calculates length of excess carpet roll (with 5m width)
- remainder = (totalrolls * 30) - totallength
- lblremainder.Caption = Str(remainder) + " metres"
- End Sub
- Private Sub cmdExit_Click()
- End
- End Sub
- Private Sub cmdReset_Click()
- txtlength.Text = ""
- txtwidth.Text = ""
- lbltotallength.Caption = "0"
- lbltotalrolls.Caption = "0"
- lblremainder.Caption = "0"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement