Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   How do I calculate the number of single rolls of wallpaper needed? (https://www.askmehelpdesk.com/showthread.php?t=637959)

  • Feb 21, 2012, 08:47 PM
    student107
    How do I calculate the number of single rolls of wallpaper needed?
    My code keeps coming out to zero and I am not seeing what I am doing wrong.


    Option Strict On
    Option Explicit On

    Public Class frmWallpaper

    Private Sub CalcRolls(ByVal decArea As Decimal, ByVal decRolls As Decimal, ByVal decRollCoverage As Decimal)

    'Calculate output of single rolls

    decRolls = CDec(decArea / decRollCoverage)

    End Sub


    Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
    'Input Variables
    Dim decLength As Decimal
    Dim decWidth As Decimal
    Dim decHeight As Decimal
    Dim decRollCoverage As Decimal

    'Processing and Output Variables
    Dim decPerimeter As Decimal
    Dim decArea As Decimal
    Dim decRolls As Decimal

    'Validation Variables
    Dim blnIsConvertedLength As Boolean
    Dim blnIsConvertedWidth As Boolean
    Dim blnIsConvertedHeight As Boolean
    Dim blnIsConvertedRollCoverage As Boolean

    'Assign Variables
    blnIsConvertedLength = Decimal.TryParse(txtLength.Text, decLength)
    blnIsConvertedWidth = Decimal.TryParse(txtWidth.Text, decWidth)
    blnIsConvertedHeight = Decimal.TryParse(txtHeight.Text, decHeight)
    blnIsConvertedRollCoverage = Decimal.TryParse(txtRollCoverage.Text, decRollCoverage)

    'Get Single Rolls
    If blnIsConvertedLength And blnIsConvertedWidth And blnIsConvertedHeight And blnIsConvertedRollCoverage = True Then
    If decLength > 0 And decWidth > 0 And decHeight > 0 And decRollCoverage > 0 Then
    decPerimeter = (decLength decWidth) * 2
    decArea = decPerimeter * decHeight

    'Call Private Sub CalcRolls
    Call CalcRolls(decArea, decRolls, decRollCoverage)


    'Display Output
    lblRolls.Text = decRolls.ToString
    Else

    'Display if number is not entered
    MessageBox.Show("Please enter a number")
    End If
    End If


    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    'ends the application
    Me.Close()
    End Sub

    Private Sub txtLength_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLength.Enter
    txtLength.SelectAll()
    End Sub
    Private Sub txtWidth_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtWidth.Enter
    txtWidth.SelectAll()
    End Sub
    Private Sub txtHeight_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtHeight.Enter
    txtHeight.SelectAll()
    End Sub
    Private Sub txtRollCoverage_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRollCoverage.Enter
    txtRollCoverage.SelectAll()
    End Sub

    Private Sub ClearLabel(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles txtLength.TextChanged, txtWidth.TextChanged, txtLength.TextChanged, txtRollCoverage.TextChanged
    lblRolls.Text = String.Empty
    End Sub


    End Class

  • All times are GMT -7. The time now is 10:18 PM.