AVERAGE CALCULATOR USING VB 6.0
















This is an example of application created using visual basic 6.0

I suggest that you create the Graphical User Interface and follow the codes below.. Good luck :)

'Program to calculate average of series of marks
'
'Up to 25 marks can be input
'Input can be letter or percent
'
'Demonstrates use of control array
'and Case structure
'
Option Explicit
Dim strMark As String
Dim sngTot As Single
Dim intCount As Integer
Dim intAtot As Integer
Dim intAmtot As Integer
Dim intBtot As Integer
Dim intCtot As Integer
Dim intTotal As Integer
Dim sngAvg As Single
Dim strAvg As String


Private Sub cmdCalc_Click()
    Dim i As Integer
    For i = 0 To 24
   
        If IsNumeric(Text1(i).Text) Then
            Select Case Text1(i).Text
                Case Is >= 95
                    strMark = "A+"
                Case Is >= 90
                    strMark = "A"
                Case Is >= 85
                    strMark = "A-"
                Case Is >= 80
                    strMark = "B+"
                Case Is >= 75
                    strMark = "B"
                Case Is >= 70
                    strMark = "B-"
                Case Is >= 65
                    strMark = "C+"
                Case Is >= 60
                    strMark = "C"
                Case Is >= 55
                    strMark = "C-"
                Case Else
                    strMark = "D"
            End Select
        Else
            strMark = UCase(Text1(i).Text)
        End If
       
        Select Case strMark
        Case "A+"
            sngTot = sngTot + 95
            intCount = intCount + 1
            intAtot = intAtot + 1
            intBtot = intBtot + 1
            intAmtot = intAmtot + 1
            intTotal = intTotal + 1
         Case "A"
            sngTot = sngTot + 90
            intCount = intCount + 1
            intAtot = intAtot + 1
            intAmtot = intAmtot + 1
            intBtot = intBtot + 1
            intTotal = intTotal + 1
        Case "A-"
            sngTot = sngTot + 85
            intCount = intCount + 1
            intBtot = intBtot + 1
            intAmtot = intAmtot + 1
            intTotal = intTotal + 1
        Case "B+"
            sngTot = sngTot + 80
            intCount = intCount + 1
            intBtot = intBtot + 1
            intTotal = intTotal + 1
        Case "B"
            sngTot = sngTot + 75
            intCount = intCount + 1
            intBtot = intBtot + 0
            intTotal = intTotal + 1
        Case "B-"
            sngTot = sngTot + 70
            intCount = intCount + 1
            intBtot = intBtot + 0
            intTotal = intTotal + 1
        Case "C+"
            sngTot = sngTot + 65
            intCount = intCount + 1
            intCtot = intCtot + 0
            intTotal = intTotal + 1
        Case "C"
            sngTot = sngTot + 60
            intCount = intCount + 1
            intCtot = intCtot + 0
            intTotal = intTotal + 1
        Case "C-"
            sngTot = sngTot + 55
            intCount = intCount + 1
            intCtot = intCtot + 0
            intTotal = intTotal + 1
        Case Else
            intCount = intCount + 0
            intTotal = intTotal + 0
        End Select
    Next i
   
    If intCount <> 0 Then
        sngAvg = (sngTot / intCount)
    End If
   
    Select Case sngAvg
        Case Is >= 95
            strAvg = "A+"
        Case Is >= 90
            strAvg = "A"
        Case Is >= 85
            strAvg = "A-"
        Case Is >= 80
            strAvg = "B+"
        Case Is >= 75
            strAvg = "B"
        Case Is >= 70
            strAvg = "B-"
        Case Is >= 65
            strAvg = "C+"
        Case Is >= 60
            strAvg = "C"
        Case Is >= 55
            strAvg = "C-"
    End Select
   
     'Calculate and display average
     'and distribution of marks
    
    lblAvg.Caption = strAvg & "    " & Format(sngAvg, "##.##") & "%"
                   
    lblA.Caption = Format((intAtot / intTotal), "##.##%")
    lblB.Caption = Format((intAmtot / intTotal), "##.##%")
    lblC.Caption = Format((intBtot / intTotal), "##.##%")
  
End Sub

Private Sub cmdCancel_Click()
    'Standard procedure to center form on screen
    'Can be used in any application
   
    Me.Left = (Screen.Width - Me.Width) / 2
    Me.Top = (Screen.Height - Me.Height) / 2
   
    Clear
End Sub

Private Sub Clear()
    Dim i As Integer
    For i = 0 To 24
        Text1(i).Text = ""
    Next i
       
    txtName.Text = ""
    txtSchool.Text = ""
       
    strMark = ""
    intAtot = 0
    intBtot = 0
    intCtot = 0
    intAmtot = 0
    intTotal = 0
    sngTot = 0
    intCount = 0
   
    lblAvg = ""
    lblA = ""
    lblB = ""
    lblC = ""
   
End Sub

Private Sub cmdPrint_Click()
    PrintForm
End Sub

Private Sub cmdQuit_Click()
    End
End Sub

Private Sub Form_Load()
    cmdCancel_Click
End Sub

Private Sub txtName_Change()

End Sub




  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comments:

Post a Comment