Here is the question that I need help to write the code for the following program in Visual Basic 2010. I am trying to write the code but it has a run time error. If your could helps me to write the code it would be greatly appreciated.

Q. Write a program that calculates the average of up to 50 numbers input by the user and stored in an array. The program should use a class named Statistics and have an AddNumber method that stores numbers into an array one at a time. The class should have a Count property that keeps track of the number of numbers stored and a method called Average that returns the average of the numbers.
Thank you for your help

If you have a run-time error, one of the following is the culprit:

1. There is a logic error in the code.
2. There is an exception which is not caught (a different kind of logic error).
3. Undetected syntax error.

The best way to find the problem is to post your code and we'll help you find the problem. Also, posting the error message would help. (array out of bound? Division by zero?...)

Sure, I can help you with that. Here's an example code in Visual Basic 2010 that addresses the requirements you mentioned:

```vb
Public Class Statistics
Private numbers() As Integer
Private count As Integer

Public Sub New()
ReDim numbers(50) ' Create an array to store up to 50 numbers
count = 0 ' Initialize the count to 0
End Sub

Public Sub AddNumber(ByVal num As Integer)
' Add the number to the array at the current count position
numbers(count) = num
count += 1 ' Increment the count by 1 to keep track of the total numbers stored
End Sub

Public Function Average() As Double
' Calculate the sum of the numbers
Dim sum As Integer = 0
For i As Integer = 0 To count - 1
sum += numbers(i)
Next

' Calculate the average by dividing the sum by the count
Dim avg As Double = sum / count
Return avg
End Function
End Class

Public Class Program
Public Shared Sub Main()
Dim stats As New Statistics()

' Prompt user to enter numbers
Console.WriteLine("Enter up to 50 numbers (or enter 'q' to quit):")

' Read numbers from user until 'q' is entered or the maximum count is reached
Dim input As String
Dim num As Integer
Do
input = Console.ReadLine()
If Integer.TryParse(input, num) Then
stats.AddNumber(num)
ElseIf input.ToLower() = "q" Then
Exit Do
End If
Loop Until stats.Count = 50

' Calculate and display the average
Console.WriteLine("Average of the numbers entered: " & stats.Average())

Console.ReadLine()
End Sub
End Class
```

Explanation:
1. The program starts with defining a class named `Statistics`, which holds the logic for managing the array of numbers and calculating the average.
2. The `Statistics` class has a private array `numbers()` to store the numbers input by the user. The current count of numbers stored is stored in the private variable `count`.
3. `AddNumber` method is used to store numbers into the array. It takes an input number as a parameter and adds it to the array at the current count position.
4. `Average` method calculates the average of the numbers by summing up all the numbers using a loop and then dividing the sum by the count of numbers.
5. The `Program` class is where the program execution starts. It creates an instance of the `Statistics` class and then prompts the user to enter up to 50 numbers.
6. The program reads the user input until either 'q' is entered or the maximum count of 50 is reached. It calls the `AddNumber` method to store each number entered by the user.
7. Finally, the program calls the `Average` method to calculate and display the average of the numbers entered.

Make sure to copy and paste the provided code into your Visual Basic 2010 environment and run the program to see the results.