Ask Experts Questions for FREE Help !
Ask
    emmet11's Avatar
    emmet11 Posts: 1, Reputation: 1
    New Member
     
    #1

    Jan 17, 2010, 04:13 PM
    why does it say i keep dividing by zero?
    This is my code and it tells me I'm dividing by zero but I don't understand why.

    Dim WallWidth As Decimal 'width of wall
    Dim WallHeight As Decimal 'height of wall
    Dim RollLength As Decimal ' length of wallpaper roll
    Dim RollWidth As Decimal ' 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)
    area = (RollLength * RollWidth)
    totroll = Convert.ToInt32(areawall / area)
    End If
    Me.lbltotal.Text = Convert.ToString(totroll)
    Scleros's Avatar
    Scleros Posts: 2,165, Reputation: 262
    Hardware Expert
     
    #2

    Jan 17, 2010, 11:54 PM

    I only see one place where you are dividing anything and the variable is area, so area is ending up with a value of 0. Stick in some messageboxes at various locations throughout the program to show variable values, or else trace through it. Int conversions can also truncate yielding unexpected results.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Dividing decimals [ 2 Answers ]

Could someone tell me how to divide this problem Joey has 0.6 as many teeth as jane. Jane has 32 teeth. How many does joey have, I came up with 53 but it doesn't seem right. Do I divide 0.06 by 32?:confused:

Dividing partnership [ 1 Answers ]

Need to understand Gale Haley and Leah Manos formed a partnership, investing $180,000 and $60,000 respectively. Determine their participation in this year's net income of $150,000 under each of the following independent assumptions: (a) no agreement concerning division of net income; (b)...

Dividing a cell [ 2 Answers ]

What is the peoriod when a cell devides to create a new cell called?

Dividing decimals [ 1 Answers ]

How todevide decimals


View more questions Search