Results 1 to 9 of 9

Thread: want to code a program a shorter way ...

  1. #1

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    Post shorter code

    although my program is pretty simple it might be hard for me to explain it ...

    my program's only purpose in life is to get me my final average of the whole year of any class ... this was pretty simple at first because my school used # grades n all i had to do was plug in those #'s into a formula ...

    however, for some reason my school changed to the letter grade system ... i know that i can easily type the # i think would be closest to the letter grade n not worry about making a whole new program ...

    however, i just want to use the combo-box n select the letter grade that i get ... now the letter grades go from a+, a, a-, b+, b, b-, c+, c, c-, d, f, f- ...

    now for me to get my final grade i have to add my 4 marking period grades n multiply them by 2 n add that to the sum of my midterm n final exam n divide the whole thing by 10 ...

    however, its going to be a hassle just to get the value of one marking period grade cause i'm gonna have to check what letter is in the combo-box (which r 12 letters which means i'm gonna have to check which letter it is until it is the right one) n then turn it into a # value ...

    now that's a lot of coding just to find one marking period grade by using letters ... n don't forget that after i find that one i have to find the other 5 grades (2,3,4 marking period n midterm n final) ...

    so does anyone know of a way that i can cut this coding down to size ... or else i'll be spending a lot of time coding ... any help is appreciated

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    Could you use the listindex property of the combo box to calculate the grade value on the fly?
    i.e. a+ is combo1.list(0), up to f- is combo1.list(11)
    So you could do something like
    Code:
    Grade=(12-Combo1.ListIndex)*8.333
    Which would make an a+ = 100, and an f- = 8.333 (You could alter this function to make the f- = 0 and the a+ = 100 or whatever), and then perform the rest of your calculations on the result.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    ///

    problem...how do you declare a+ or a-

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Guest
    You mean as in they might cause conflicts with the operators + and -? Then you can name them Ap and Am. p stands for Plus and m stands for minus.

  5. #5

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    Unhappy good idea but

    andrew your solution is a good idea but the # values i need to get can't come out with the formula ... at least i don't see how ...

    a+ = 97, a = 93, a- = 90, b+ = 87, b = 83, b- = 80,
    c+ = 77, c = 73, c- = 70, d = 65, f = 60, f- = 50

    i don't think changing any #'s in the formula u mentioned can give me those exact letter values ...

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    ...Ap Am A

    another approach is to use public Constants
    ie.bas module

    Public Ap,A,Am as Integer

    Public Const Ap = 97
    Public Const A = 93
    Public Const Am = 90

    then just use the values as you would numbers
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    Guest
    Put them in an Enum to reduce time.

  8. #8
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    You could use the ItemData property of the ComboBox when you add the grades at the beginning

    Code:
    Private Sub Form_Load()
        With Combo1
            .AddItem "A+", 0: .ItemData(0) = 97
            .AddItem "A", 1: .ItemData(1) = 93
            .AddItem "A-", 2: .ItemData(2) = 90
            .AddItem "B+", 3: .ItemData(3) = 87
            .AddItem "B", 4: .ItemData(4) = 83
            .AddItem "B-", 5: .ItemData(5) = 80
            .AddItem "C+", 6: .ItemData(6) = 77
            .AddItem "C", 7: .ItemData(7) = 73
            .AddItem "C-", 8: .ItemData(8) = 70
            .AddItem "D", 9: .ItemData(9) = 65
            .AddItem "F", 10: .ItemData(10) = 60
            .AddItem "F-", 11: .ItemData(11) = 50
            .ListIndex = 0
        End With
    End Sub
    
    Private Sub Combo1_Click()
        Grade = Combo1.ItemData(Combo1.ListIndex)
    '(Or whatever you want to do with it)
    End Sub

  9. #9
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    If you go as far as to enumerate the values then give them proper names for easier reading later.

    Code:
    Enum GradesInfo
      gradeAPlus = 97
      gradeA = 93
      gradeAMinus = 90
      gradeBPlus = 87
      gradeB = 83
    etc etc

    DocZaf
    {;->

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