Link to home
Start Free TrialLog in
Avatar of HawaiiDragon
HawaiiDragon

asked on

help creating a method

hello experts I need help creating a method in vb.
I am working on a grade tracking program for one of our new teachers for her to test during the summer sememster. As by the request of the product owner I need a method that is going to store the numbers into an array one at a time. I will eventually be putting this on a button click event but for now its going into its own class I will paste what I have below thank you very much
Public Class Form1

 

    Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click

    End Sub
End Class

------------- this is my stastics class that the info has to go to


Public Class Statistics
    Dim TestingSum = 0
    Dim NumberSum = 0
    Dim SuperString As String = ""
    Dim NumberList As New List(Of Decimal)

    Dim NumberCounter = NumberList.Count
    Dim NumberCounterExtreem = NumberCounter - 1


    Public Function StartTheCounting() As String




        Return
    End Function




End Class

Open in new window

Avatar of HawaiiDragon
HawaiiDragon

ASKER

Sorry the number to get sent in in TextBox1.Text
Avatar of Brad Brett
Do you mean that you want to push the numbers inside array?
Yes and I have gone a little further now too. I was able to make it work inside the main program but I need it to reach out to the class to calculate the way they want it to
Public Class Form1

    Dim Testingnum = 0
    Dim FinalNumber = 0
    Dim SuperString As String = ""
    Dim NumberList As New List(Of Decimal)

    Dim NumberCounter = NumberList.Count
    Dim NumberCounterExtreem = NumberCounter - 1

    Public Sub btnCalculateAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateAverage.Click
        For X = 0 To NumberCounterExtreem
            FinalNumber = FinalNumber + NumberList(X)
            tbanswer.Text = FinalNumber / NumberList.Count
            tbanswer.Text = tbanswer.Text / NumberList.Count

        Next
    End Sub

    Public Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click

        Dim TheNumberEntered = tbnumber.Text
        ' If IsNumeric(tbnumber) Then
        NumberList.Add(Convert.ToDecimal(TheNumberEntered))
        Testingnum = Testingnum + 1
        tbnumber.Text = Nothing

        NumberCounterExtreem = NumberList.Count - 1
        FinalNumber = 0

        For X = 0 To NumberCounterExtreem
            FinalNumber = FinalNumber + NumberList(X)
            lblCounter.Text = FinalNumber / NumberList.Count
        Next

        '  End If


    End Sub
End Class
--------------------------------------------------
Class Statistics.vb
_________________________________________
Public Class Statistics
    Dim TestingSum = 0
    Dim NumberSum = 0
    Dim SuperString As String = ""
    Dim NumberList As New List(Of Decimal)

    Dim NumberCounter = NumberList.Count
    Dim NumberCounterExtreem = NumberCounter - 1


    Public Function StartTheCounting() As String





    End Function




End Class

Open in new window

Please explain - how do they want it to work? What do you need help with? It helps if the exact question is formulated.
Okay so I have this score calculator for last min checking of thier math in thier grade books. They imput a number in the text box called 'tbnumber' they then click on Record Number called 'btnRecord' and it takes the number that is put into the textbox converts it to an int and then stores it in an array. When they click on the Calculate Average button called 'btnCalculateAverage' it then displays the average of the scores in a textbox called tbanswer. Now they want all the calculations to come from a secondary class called statisstics. I have NO IDEA how to make the first form work with a secondary class flie. I have updated more code and it is below
Public Class Form1

    Dim Testingnum = 0
    Dim FinalNumber = 0
    Dim SuperString As String = ""
    Dim NumberList As New List(Of Decimal)

    Dim NumberCounter = NumberList.Count
    Dim NumberCounterExtreem = NumberCounter - 1

    Public Sub btnCalculateAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateAverage.Click
        For X = 0 To NumberCounterExtreem
            FinalNumber() = FinalNumber + NumberList(X)
            tbanswer.Text = FinalNumber / NumberList.Count
            tbanswer.Text = tbanswer.Text / NumberList.Count
            Return

        Next
    End Sub

    Public Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click

        Dim TheNumberEntered = tbnumber.Text
        ' If IsNumeric(tbnumber) Then
        NumberList.Add(Convert.ToDecimal(TheNumberEntered))
        Testingnum = Testingnum + 1
        tbnumber.Text = Nothing

        NumberCounterExtreem = NumberList.Count - 1
        FinalNumber = 0

        For X = 0 To NumberCounterExtreem
            FinalNumber = FinalNumber + NumberList(X)
            lblCounter.Text = FinalNumber / NumberList.Count
        Next

        ' End If


    End Sub
End Class
------
statistics code 
------
Public Class Statistics
    Dim TestingSum = 0
    Dim NumberSum = 0
    Dim SuperString As String = ""
    Dim NumberList As New List(Of Decimal)

    Dim NumberCounter = NumberList.Count
    Dim NumberCounterExtreem = NumberCounter - 1


    Public Function StartTheCounting() As String





    End Function




End Class

Open in new window

SOLUTION
Avatar of Brad Brett
Brad Brett
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@kertkert: I just mentioned using Stacks in the links I posted.
yes now how would I get the button clicks on the first page to access this and then populate everything pretty please?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'd mark that as an answer.
Thank you all! I was able to modify a little here and there and below is my final code Thank you for all the help

Public Class Form1


    Private Stats As New Statistics

   

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Stats.Clear()
        lblAnswer.Text = "Average: N/A"
    End Sub

   
    Private Sub btnRecord_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
        Dim TheNumberEntered As Decimal
        If Decimal.TryParse(tbnumber.Text, TheNumberEntered) Then
            Stats.AddNumber(TheNumberEntered)
            tbnumber.Text = Nothing
            tbnumber.Focus()

        Else
            MessageBox.Show("Invalid Grade Entered")
        End If
    End Sub

    Private Sub btnCalculateAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateAverage.Click
        tbanswer.Text = Stats.Average


    End Sub
End Class

Public Class Statistics

    Private NumberList As New List(Of Decimal)

    Public Sub AddNumber(ByVal dec As Decimal)
        NumberList.Add(dec)
    End Sub

    Public ReadOnly Property Average() As Decimal
        Get
            If NumberList.Count > 0 Then
                Dim sum As Decimal
                For Each dec As Decimal In NumberList
                    sum = sum + dec
                Next
                Return sum / CDec(NumberList.Count)
            Else
                Return 0
            End If
        End Get
    End Property

    Public Sub Clear()
        NumberList.Clear()
    End Sub



End Class