Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim length, iwidth, a, b, totallength, totalrolls, remainder As Integer
  2.  
  3. Private Sub cmdCalculate_Click()
  4. 'resets length and width variables
  5. length = 0
  6. iwidth = 0
  7. 'retrieves length and width from the textboxes
  8. length = Val(txtlength.Text)
  9. iwidth = Val(txtwidth.Text)
  10. 'tests that length and width are numbers
  11. If Not IsNumeric(txtlength.Text) Then
  12.     MsgBox ("You must enter a number for the length.")
  13.     txtlength.Text = ""
  14.     txtlength.SetFocus
  15. End If
  16. If Not IsNumeric(txtwidth.Text) Then
  17.     MsgBox ("You must enter a number for the width.")
  18.     txtwidth.Text = ""
  19.     txtwidth.SetFocus
  20. End If
  21. 'tests that length and width are within 1 and 20 metres
  22. If IsNumeric(txtlength.Text) Then
  23. If length < 1 Or length > 20 Then
  24.     MsgBox ("You must enter a length between 1 and 20")
  25.     txtlength.Text = ""
  26.     length = 0
  27.     iwidth = 0
  28.     txtlength.SetFocus
  29. End If
  30. End If
  31. If IsNumeric(txtwidth.Text) Then
  32. If iwidth < 1 Or iwidth > 20 Then
  33.     MsgBox ("You must enter a width between 1 and 20")
  34.     txtwidth.Text = ""
  35.     txtwidth.SetFocus
  36.     length = 0
  37.     iwidth = 0
  38. End If
  39. End If
  40. 'calculates total length of carpet needed
  41. a = iwidth \ 5
  42.  
  43. If iwidth Mod 5 > 0 Then
  44.  a = a + 1
  45. End If
  46.  
  47. totallength = a * length
  48. lbltotallength.Caption = Str(totallength) + " metres"
  49. 'calculates total rolls needed
  50. b = (a * length)
  51.  
  52. totalrolls = b \ 30
  53.  
  54. If b Mod 30 > 0 Then
  55.     totalrolls = totalrolls + 1
  56. End If
  57.  
  58. lbltotalrolls.Caption = totalrolls
  59. 'calculates length of excess carpet roll (with 5m width)
  60. remainder = (totalrolls * 30) - totallength
  61.  
  62. lblremainder.Caption = Str(remainder) + " metres"
  63.  
  64. End Sub
  65.  
  66. Private Sub cmdExit_Click()
  67.  
  68. End
  69.  
  70. End Sub
  71.  
  72. Private Sub cmdReset_Click()
  73.  
  74. txtlength.Text = ""
  75. txtwidth.Text = ""
  76. lbltotallength.Caption = "0"
  77. lbltotalrolls.Caption = "0"
  78. lblremainder.Caption = "0"
  79.  
  80. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement