littleivyle
Jan 3, 2010, 08:07 PM
I have to create an application that calculates the number of wallpaper rolls to cover a wall. I also have to use one or more independent sub or function procedures. So far I have this but it keeps telling me I can't divide by zero.
'declare variables
Dim WallWidth As Integer 'width of wall
Dim WallHeight As Integer 'height of wall
Dim RollLength As Integer ' length of wallpaper roll
Dim RollWidth As Integer ' width of wallpaper roll
Dim areawall As Integer
Dim area As Integer
Dim NumofRoll As Integer 'number of rolls needed
Dim totroll As Integer
'Text box is numeric
If txtwidthwall.Text <> "" Then
'assign text box
If IsNumeric(txtwidth.Text) Then
WallWidth = Convert.ToInt32(txtwidth.Text)
ElseIf IsNumeric(txtheight.Text) Then
WallHeight = Convert.ToInt32(txtheight.Text)
ElseIf IsNumeric(txtlengthwall.Text) Then
RollLength = Convert.ToInt32(txtlengthwall.Text)
ElseIf IsNumeric(txtwidthwall.Text) Then
RollWidth = Convert.ToInt32(txtwidthwall.Text)
Else
MessageBox.Show("Please enter number.", _
"Wallpaper", MessageBoxButtons.OK, _
MessageBoxIcon.Information, _
MessageBoxDefaultButton.Button1)
End If
areawall = WallWidth * WallHeight
Call Arearoll(RollLength, RollWidth, Area)
totroll = areawall / area
End If
Me.lbltotal.Text = Convert.ToString(totroll)
End Sub
Private Sub Arearoll(ByVal length As Integer, ByVal width As Integer, ByRef area As String)
'calculates the number of rolls
area = length * width
'declare variables
Dim WallWidth As Integer 'width of wall
Dim WallHeight As Integer 'height of wall
Dim RollLength As Integer ' length of wallpaper roll
Dim RollWidth As Integer ' width of wallpaper roll
Dim areawall As Integer
Dim area As Integer
Dim NumofRoll As Integer 'number of rolls needed
Dim totroll As Integer
'Text box is numeric
If txtwidthwall.Text <> "" Then
'assign text box
If IsNumeric(txtwidth.Text) Then
WallWidth = Convert.ToInt32(txtwidth.Text)
ElseIf IsNumeric(txtheight.Text) Then
WallHeight = Convert.ToInt32(txtheight.Text)
ElseIf IsNumeric(txtlengthwall.Text) Then
RollLength = Convert.ToInt32(txtlengthwall.Text)
ElseIf IsNumeric(txtwidthwall.Text) Then
RollWidth = Convert.ToInt32(txtwidthwall.Text)
Else
MessageBox.Show("Please enter number.", _
"Wallpaper", MessageBoxButtons.OK, _
MessageBoxIcon.Information, _
MessageBoxDefaultButton.Button1)
End If
areawall = WallWidth * WallHeight
Call Arearoll(RollLength, RollWidth, Area)
totroll = areawall / area
End If
Me.lbltotal.Text = Convert.ToString(totroll)
End Sub
Private Sub Arearoll(ByVal length As Integer, ByVal width As Integer, ByRef area As String)
'calculates the number of rolls
area = length * width