microsoft visual basic 2008 express

July 12, 2009 at 13:55:19
Specs: Windows Vista
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 / coverage

End 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

See More: microsoft visual basic 2008 express

Report •

July 12, 2009 at 15:40:01
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.


Report •

July 12, 2009 at 16:27:59
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 = 140

H= 12 * 140 = 1680

C= 200
My single roll should be 8.4

Rolls = 8.4"

Report •

Related Solutions

Ask Question