I am new to VB and usually work in C but was wanting to see if someone can take a look at this program and give me any advice I would really appreciate it and also let me know if I am close...

I am going to first give instructions and then the code and please let me know if you can see what im doing wrong and if you need the actual form and what it looks like please email me your address...

Programming Assignment One
Bearcat Green, a local lawn and garden enterprise, has asked you to create a program to assist their sales staff with correctly computing the amount of seed, fertilizer, or other product to sell a client for a given coverage area.
Normally, a coverage area is expressed in some rectangular area with a product amount associated with that coverage area. For example, a fertilizer product may recommend using 1 pound per 5000 square feet.
Clients bring in the dimensions of the area that they wish to seed or feed. The dimensions may be expressed in inches, feet, or yards. The program you develop should take a decimal number value for the length and width of the area to be treated.. The program user will define the units – inches, feet, or yards – at runtime.
Each product sold comes with a recommended coverage value. This coverage value normally indicates a value in pounds and the square feet or square yards that are covered. See the example above.
The programs output should indicate how many pounds of product the client should purchase

HERE IS MY CODE...

Public Class bearcatGreenProductCalculator

'DECLARE VARIABLES
Dim inchesLength As Double
Dim inchesWidth As Double
Dim inchesSquareFeet As Double
Dim inchesSquareYards As Double
Dim feetLength As Double
Dim feetWidth As Double
Dim feetSquareFeet As Double
Dim feetSquareYards As Double
Dim yardsLength As Double
Dim yardsWidth As Double
Dim yardsSquareFeet As Double
Dim yardsSquareYards As Double

Private Sub inchesRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
'IF STATEMENT FOR INCHES RADIO BUTTON IS CHECKED
If inchesRadioButton.Checked = True Then
lengthTextBox = inchesLength
widthTextBox = inchesWidth
inchesSquareFeet = (inchesLength / 12) * (inchesWidth / 12)
inchesSquareYards = ((inchesLength / 12) / 3) * ((inchesWidth / 12) / 3)
End If
End Sub

Private Sub feetRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles feetRadioButton.CheckedChanged
'IF STATEMENT FOR FEET RADIO BUTTON IS CHECKED
If feetRadioButton.Checked = True Then
lengthTextBox = feetLength
widthTextBox = feetWidth
feetSquareFeet = feetLength * feetWidth
feetSquareYards = (feetLength \ 3) * (feetWidth \ 3)
End If
End Sub

Private Sub yardsRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yardsRadioButton.CheckedChanged
'IF STATEMENT FOR YARDS RADIO BUTTON IS CHECKED
'If yardsRadioButton.Checked = True Then
lengthTextBox = yardsLength
widthTextBox = yardsWidth
yardsSquareFeet = (yardsLength * 3) * (yardsWidth * 3)
yardsSquareYards = yardsLength * yardsWidth

End Sub

Recommended Answers

All 12 Replies

sorry for the incorrect tags

HERE IS MY CODE...

Public Class bearcatGreenProductCalculator

'DECLARE VARIABLES
Dim inchesLength As Double
Dim inchesWidth As Double
Dim inchesSquareFeet As Double
Dim inchesSquareYards As Double
Dim feetLength As Double
Dim feetWidth As Double
Dim feetSquareFeet As Double
Dim feetSquareYards As Double
Dim yardsLength As Double
Dim yardsWidth As Double
Dim yardsSquareFeet As Double
Dim yardsSquareYards As Double

Private Sub inchesRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
'IF STATEMENT FOR INCHES RADIO BUTTON IS CHECKED
If inchesRadioButton.Checked = True Then
lengthTextBox = inchesLength
widthTextBox = inchesWidth
inchesSquareFeet = (inchesLength / 12) * (inchesWidth / 12)
inchesSquareYards = ((inchesLength / 12) / 3) * ((inchesWidth / 12) / 3)
End If
End Sub

Private Sub feetRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles feetRadioButton.CheckedChanged
'IF STATEMENT FOR FEET RADIO BUTTON IS CHECKED
If feetRadioButton.Checked = True Then
lengthTextBox = feetLength
widthTextBox = feetWidth
feetSquareFeet = feetLength * feetWidth
feetSquareYards = (feetLength \ 3) * (feetWidth \ 3)
End If
End Sub

Private Sub yardsRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yardsRadioButton.CheckedChanged
'IF STATEMENT FOR YARDS RADIO BUTTON IS CHECKED
'If yardsRadioButton.Checked = True Then
lengthTextBox = yardsLength
widthTextBox = yardsWidth
yardsSquareFeet = (yardsLength * 3) * (yardsWidth * 3)
yardsSquareYards = yardsLength * yardsWidth

End Sub
Member Avatar for Unhnd_Exception

I would convert to feet right before you calculate.

then convert to sq yards or sq feet.

Private Sub BtnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

   If String.IsNullOrEmpty(txtLength.Text) OrElse Not IsNumeric(txtLength.Text) OrElse txtLength.Text <= 0 Then
      'bad length
       Exit Sub
   End If

   If String.IsNullOrEmpty(txtWidth.Text) OrElse Not IsNumeric(txtWidth.Text) OrElse txtWidth.Text <= 0 Then
      'bad weight
      Exit Sub
   End If

   Dim ftLength, ftWidth As Double
   Dim sqFt, sqYds As Double

   If rdoIn.Checked Then
       ftLength = txtLength.Text / 12
       ftWidth = txtWidth.Text / 12

   ElseIf rdoYd.Checked Then
       ftLength = txtLength.Text * 3
       ftWidth = txtWidth.Text * 3
   
   Else
       ftLength = txtLength.Text
       ftWidth = txtWidth.Text
        
   End If


   sqFt = ftLength * ftWidth
   sqYds = sqFt / 9

End Sub

I made the changes but it does not compute and now my quit button does not work. I think it may help if I give kind of a sketch on what my form looks like so I apologize if it looks messy but its the best I can do...here is how it looks

Coverage Area
o inches o feet o yards compute button

quit button

length [length textbox is here]
width [width textbox is here]

product information
[pounds textbox is here] pounds(s) covers

[square feet or square yards textbox] o square feet
o square yards

Product needed
[output of compute button textbox] pounds required

Ok that is the form I hope this helps so what I need to do is enter a radio button for inches, feet, or yards. Then I have to enter the length and width. FinallI need to ask for a bag when so many pounds overs either a certain amount of square feet or square yards and when I click on compute the textbox at the bottom should tell me how many pounds I need. Here is my code...

Public Class bearcatGreenProductCalculator



    Private Sub computeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles computeButton.Click

        'EXIT PROGRAM IF LENGTH IS NOT CORRECT
        If String.IsNullOrEmpty(txtLength.Text) OrElse Not IsNumeric(txtLength.Text) OrElse txtLength.Text <= 0 Then
            Exit Sub

        End If

        EXIT PROGRAM IF WIDTH IS NOT CORRECT
        If String.IsNullOrEmpty(txtWidth.Text) OrElse Not IsNumeric(txtWidth.Text) OrElse txtWidth.Text <= 0 Then
            Exit Sub

        End If

        'DECLARE VARIABLES
        Dim ftLength, ftWidth As Double
        Dim sqFt, sqYds As Double

        'IF STATEMENT FOR IF THE INCHES RADIO BUTTON IS CHECKED
        If inchesRadioButton.Checked Then
            ftLength = txtLength.Text / 12
            ftWidth = txtWidth.Text / 12

            'IF STATEMENT FOR IF THE YARDS RADIO BUTTON IS CHECKED
        ElseIf yardsRadioButton.Checked Then
            ftLength = txtLength.Text * 3
            ftWidth = txtWidth.Text * 3

            'IF FEET RADIO BUTTON IS CHECKED
        Else
            ftLength = txtLength.Text
            ftWidth = txtWidth.Text

        End If
        sqFt = ftLength * ftWidth
        sqYds = sqFt / 9

    End Sub


    Private Sub quitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles quitButton.Click
        'CLOSE THE PROGRAM IF QUIT BUTTON IS CLICKED
        Close()
    End Sub
End Class

dang it the form I tried to create did not come out how i wanted it to so let me explain it instead as I did earlier.

I need to click a radio button for inches, feet, or yards. Then I have to enter the length and width of the farm. Finally I need to ask for a bag with so many pounds that covers either a certain amount of square feet or square yards from a radio button that I need to click and when I click on compute the textbox at the bottom should tell me how many pounds I need.

Or if someone wants to PM me their email I can send a screen shot unless its possible to do it on the forum

Member Avatar for Unhnd_Exception
Private Sub BtnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

        If String.IsNullOrEmpty(txtLength.Text) OrElse Not IsNumeric(txtLength.Text) OrElse txtLength.Text <= 0 Then
            'bad length
            Exit Sub
        End If

        If String.IsNullOrEmpty(txtWidth.Text) OrElse Not IsNumeric(txtWidth.Text) OrElse txtWidth.Text <= 0 Then
            'bad weight
            Exit Sub
        End If

        If String.IsNullOrEmpty(txtCoverage.Text) OrElse Not IsNumeric(txtCoverage.Text) OrElse txtCoverage.Text <= 0 Then
            'bad coverage
            Exit Sub
        End If

        Dim ftLength, ftWidth As Double

        If rdoIn.Checked Then
            ftLength = txtLength.Text / 12
            ftWidth = txtWidth.Text / 12

        ElseIf rdoYd.Checked Then
            ftLength = txtLength.Text * 3
            ftWidth = txtWidth.Text * 3

        Else
            ftLength = txtLength.Text
            ftWidth = txtWidth.Text

        End If

        If rdoSqFt.Checked Then
            lblTotalLbs.Text = ftLength * ftWidth / txtCoverage.Text
        Else
            lblTotalLbs.Text = ftLength * ftWidth / 9 / txtCoverage.Text
        End If

    End Sub

still got a few problems which is my fault for not explaining it. My problem is when I click on like the feet, inches, yards radio button is shows it is clicked but when I click on the second part of the form of square feet and square yards the radio button I clicked on feet, inches, and yards is removed. I am wondering if I need to put these in some kind of a radio button box if this even exists? Also compute and quit buttons don't do anything which may be the reason for the radio button issue

Member Avatar for Unhnd_Exception

Put the square yards and square feet radios in a panel.

My bad.

i found the groupbox but may have additional questions thanks

ehhh Sorry again but for some reason when I click on compute and quit nothing happens which is kind of strange because when I tried the quit button at school on Friday it worked fine...if any of you guys can see anything with the changed I made please let me know...

Public Class bearcatGreenProductCalculator



    Private Sub computeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles computeButton.Click

        'EXIT PROGRAM IF LENGTH IS NOT CORRECT
        If String.IsNullOrEmpty(txtLength.Text) OrElse Not IsNumeric(txtLength.Text) OrElse txtLength.Text <= 0 Then
            Exit Sub

        End If

        'EXIT PROGRAM IF WIDTH IS NOT CORRECT
        If String.IsNullOrEmpty(txtWidth.Text) OrElse Not IsNumeric(txtWidth.Text) OrElse txtWidth.Text <= 0 Then
            Exit Sub

        End If

        'DECLARE VARIABLES
        Dim ftLength, ftWidth As Double
        Dim sqFt, sqYds As Double

        'IF STATEMENT FOR IF THE INCHES RADIO BUTTON IS CHECKED
        If inchesRadioButton.Checked Then
            ftLength = txtLength.Text / 12
            ftWidth = txtWidth.Text / 12

            'IF STATEMENT FOR IF THE YARDS RADIO BUTTON IS CHECKED
        ElseIf yardsRadioButton.Checked Then
            ftLength = txtLength.Text * 3
            ftWidth = txtWidth.Text * 3

            'IF FEET RADIO BUTTON IS CHECKED
        Else
            ftLength = txtLength.Text
            ftWidth = txtWidth.Text

        End If
        sqFt = ftLength * ftWidth
        sqYds = sqFt / 9


        If squareFeetRadioButton.Checked Then

            lblTotalLbs.Text = ftLength * ftWidth / txtCoverage.Text

        ElseIf squareYardsRadioButton.Checked Then

            lblTotalLbs.Text = ftLength * ftWidth / 9 / txtCoverage.Text

        End If

    End Sub


    Private Sub quitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles quitButton.Click
        'CLOSE THE PROGRAM IF QUIT BUTTON IS CLICKED
        Close()
    End Sub
End Class
Member Avatar for Unhnd_Exception

Don't see any reason they shouldn't work.

it may just be something with the install of studio ill check it on monday

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.