Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

help creating a method

Posted on 2011-05-05
12
Medium Priority
?
347 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:HawaiiDragon
  • 5
  • 3
  • 3
  • +1
12 Comments
 

Author Comment

by:HawaiiDragon
ID: 35700307
Sorry the number to get sent in in TextBox1.Text
0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35700392
Do you mean that you want to push the numbers inside array?
0
 

Author Comment

by:HawaiiDragon
ID: 35700592
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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:kertkert
ID: 35700663
Please explain - how do they want it to work? What do you need help with? It helps if the exact question is formulated.
0
 

Author Comment

by:HawaiiDragon
ID: 35700733
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

0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 100 total points
ID: 35700776
0
 
LVL 1

Assisted Solution

by:kertkert
kertkert earned 300 total points
ID: 35700816
You should use stacks if you want to store sequential data.

Is this what you are looking for?
Public Class Statistics

        Dim Items As Collections.Generic.Stack(Of Decimal)

        Public ReadOnly Property Average As Decimal
            Get
                Dim Total As Decimal = 0
                For Each Item In Items
                    Total += Item
                Next
                Return Total / Items.Count
            End Get
        End Property

        Sub AddGrade(ByVal Grade As String)
            If IsNumeric(Grade) Then
                Items.Push(Decimal.Parse(Grade))
            End If
        End Sub
      
    End Class

Open in new window

0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35700831
@kertkert: I just mentioned using Stacks in the links I posted.
0
 

Author Comment

by:HawaiiDragon
ID: 35700834
yes now how would I get the button clicks on the first page to access this and then populate everything pretty please?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1600 total points
ID: 35700870
Something like:
Public Class Form1

    Private Stats As New Statistics

    Public Sub btnRecord_Click(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)
            lblAnswer.Text = "Average: " & Stats.Average
        Else
            MessageBox.Show("Invalid Grade Entered")
        End If
    End Sub

    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

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

Open in new window

0
 
LVL 1

Expert Comment

by:kertkert
ID: 35700893
I'd mark that as an answer.
0
 

Author Closing Comment

by:HawaiiDragon
ID: 35701051
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question