I am trying to teach myself VB 2008. I am trying to get a function statement to work. I am not sure what I am doing wrong.

Here is my code.

Private Function SingleRoll(ByVal area As Integer, _

ByVal coverage As Integer) As Integer' calculate the number of rolls

Return SingleRoll = area / coverageEnd Function

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim length As Integer

Dim width As Integer

Dim height As Integer

Dim perimeter As Integer

Dim area As Integer

Dim rolls As Integer

Dim intAnswer As Integer' calculate the perimeter

perimeter = 2 * length + 2 * Width' calculate the area

area = perimeter * Height' use function to calculate the sum or product

Return SingleRoll(area, coverage)End Sub

I dont know what you are trying to do but there a few obviouse errors. You have Return SingleRoll = area / coverage in the singleRoll function which is fine.

You also have Return SingleRoll(area, coverage) in the btnCalc_Click function which is not correct notwhichstanding that you cannot return the product of a function from outside the function.

You are also attempting to return a value from a subroutine which is not allowed.

If you are attempting to call the SingleRoll function from the btnCalc_Click subroutine cut out the return.

Nowhere in the btnCalc_click function are the variables given values before you start doing calculations on them.

perimeter = 2 * length + 2 * Width is meaningless becasue they will always be zero as will height.

Stuart

Thank you for your help. I thought that I had defined them to get the value in the length field. ect. This is what I am trying to do. L=20 20 * 2 = 40

W= 50 50 * 2 = 100

40+100 = 140H= 12 * 140 = 1680

C= 200

1680/200

My single roll should be 8.4Rolls = 8.4"

Ask Your Question

Weekly Poll

Do you think Google should sell budget phones in the US?

Discuss in The Lounge

Poll History