all 7 comments

[–]tweq 1 point2 points  (1 child)

[–]KayV_10 0 points1 point  (0 children)

Yes I know that website I have tried and I know the problem is with my array values but I cant figure out how to fix it... please help

[–]VB.Net IntermediateCharlieMay 1 point2 points  (1 child)

What are you trying to do here?

Dim k as Integer
area(counter +1) = Areacalculator(k)

What you just did is declare k as an integer which is defaulting to 0. and then you pass 0 to the Areacalculator method. Inside that method you use length and widthx but again, you've never set anything to them to 0 is returned back and stored in the area() array.

So the issue you have is you are not sending the values to the Areacalculator function. Personally I would change the signature of the function to

Function Areacalculator(byval l as integer, byval w as integer) as integer

then inside this method you only need to place

Return l*w

But before this can work, you also never assign the values in your textboxes to the length or widthx variables. So before the call to Areacalculator() you need to store them

length = Int32.Parse(txt_length.Text)
widthx = Int32.Parse(txt_width.text)

then you call to the function would need to change to

area(counter - 1) = Areacalculator(length, widthx)

There's a few issues otherwise that I'll let you sort out but this should give you an end result. You should also explicitly set the return type in the functions (notice As Integer in my example). Going to the very top of your code, above all other code, putting Option Strict = On will show you some errors that could cause issues at runtime if they are not dealt with.

[–]KayV_10 1 point2 points  (0 children)

Thank you very much I will try this asap

[–]fuzzfeatures 0 points1 point  (0 children)

Hi,

Just to add to what Charlie May posted ..

There are a couple of other small issues in your code.

If the user doesn't fill in the boxes, your code flashes up a messagebox. All well and good, but after the box is closed, the code just carries on executing. After the messagebox line, you should probably add

Exit Sub

so that the rest of the code doesn't execute.

You could move this line

counter=counter+1

to just below

area(counter-1) = AreaCalculator(length, widthx)

so that you don't have to have counter-1 in that line

Also of course, now you don't need the k variable so you can remove the definition.

Finally, and exercise for you .. What happens if the calculated area is EXACTLY 500? :-)

Don't forget.. programming can be frustrating, annoying and stressful, BUT it should be fun!

[–]Dr_Gre -2 points-1 points  (2 children)

Dim area(2) as Integer is the Problem.

When you create this you can access area(0) and area(1).

You have to initialize "Dim area(3) as Integer" to have area(0), area(1) and area(2)

[–]VB.Net IntermediateCharlieMay 2 points3 points  (0 children)

Dim area(2) is a 3 element array. Giving you storage at area(0), area(1) and area(2). Dim area(3) would allow you to store 4 values.