Results 1 to 6 of 6

Thread: Classification Estimator with a Function-Help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    26

    Classification Estimator with a Function-Help

    Average Mark Classification
    >=70 1st
    60 -69 2.1
    50-59 2.2
    40-59 3rd
    <39 Unclassified

    I want to write a program to estimate the degree of classification from an average mark. For example, an average mark of 55% shd give 2.2 classification.


    I need to add a Function that shd take a single parameter value for the average mark, and return the calssification average.

    Here are my design: I am new to this and need code solution to this please.
    Attached Images Attached Images  

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Classification Estimator with a Function-Help

    You can use a Select Case statement to find what range a mark falls in. Start by reading the appropriate documentation, which will tell you all you need to know.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Classification Estimator with a Function-Help

    vb Code:
    1. Dim Result As String
    2.         Select Case Mark
    3.             Case Is >= 70
    4.                 Result = "1st"
    5.             Case Is >= 60
    6.                 Result = "2.1"
    7.             Case Is >= 50
    8.                 Result = "2.2"
    9.             Case Is >= 40
    10.                 Result = "3rd"
    11.             Case Else
    12.                 Result = "Unclassified"
    13.         End Select

    Kris

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Classification Estimator with a Function-Help

    God forbid anyone should be allowed to do their own homework.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    26

    Re: Classification Estimator with a Function-Help

    Hi Jmc,

    Thanks for your response but how do i display the classifications on the textbox called txtClassify assuming i click on button Estimate and type in a particular mark into the textbox called txtAvgMark

    Thanks.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Classification Estimator with a Function-Help

    here's my attempt. textbox1 is avg mark, textbox2 is classification:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         Dim values As New List(Of Object())
    5.         values.Add(New Object() {70, -1, "1st"})
    6.         values.Add(New Object() {60, 69, "2.1"})
    7.         values.Add(New Object() {50, 59, "2.2"})
    8.         values.Add(New Object() {40, 59, "3rd"})
    9.         values.Add(New Object() {0, 39, "Unclassified"})
    10.         Dim avgMark As Decimal
    11.         If Decimal.TryParse(TextBox1.Text, avgMark) Then
    12.             TextBox2.Text = (From v In values _
    13.                              Where avgMark >= CInt(v(0)) AndAlso avgMark <= If(CInt(v(1)) = -1, avgMark + 1, CInt(v(1))) _
    14.                             Select CStr(v(2))).FirstOrDefault
    15.         End If
    16.     End Sub
    17.  
    18. End Class

    to put that in a function with a single parameter:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         Dim avgMark As Decimal
    5.         If Decimal.TryParse(TextBox1.Text, avgMark) Then
    6.             TextBox2.Text = getClassification(avgMark)
    7.         End If
    8.     End Sub
    9.  
    10.     Private Function getClassification(ByVal avg As Decimal) As String
    11.         Dim values As New List(Of Object())
    12.         values.Add(New Object() {70, -1, "1st"})
    13.         values.Add(New Object() {60, 69, "2.1"})
    14.         values.Add(New Object() {50, 59, "2.2"})
    15.         values.Add(New Object() {40, 59, "3rd"})
    16.         values.Add(New Object() {0, 39, "Unclassified"})
    17.  
    18.         Return (From v In values _
    19.                              Where avg >= CInt(v(0)) AndAlso avg <= If(CInt(v(1)) = -1, avg + 1, CInt(v(1))) _
    20.                             Select CStr(v(2))).FirstOrDefault
    21.  
    22.     End Function
    23.  
    24. End Class
    Last edited by .paul.; Oct 6th, 2011 at 10:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width