Üye Kayıt Üye Giriş

Ortalama Hesaplama

Ortalama Hesaplama

'Projeye Eklenecekler
'txtScores(0) : Edit
'txtScores(1) : Edit
'txtScores(2) : Edit
'txtScores(3) : Edit
'txtScores(4) : Edit
'txtAnswer : Edit
'cmdCalculate : CommandButton
'cmdClear : CommandButton
'cmdExit : CommandButton

' Calculate average scores
'For the purpose of this demo I've used text boxes.
'Ideally one would use labels rather than text boxes
'for displaying scores. That way we don't let the
'user cheat changing scores ;-)

' :-: Give credit where credit is due :-:

'I read an answer to a question in one of the vb
'news groups titled "Sums in VB3" by Markus
'markus.lausen@amd.com and ended up trying it myself
'So thanks go to Markus wherever you are.

'Also used in this demo is some code by Adnan Hasanovic
'which can be found at:
'Nice 3D Effect, try it!

'Email: i-am@thepub.co.za

Option Explicit

Dim counter As Integer
Dim sum As Integer

Private Sub cmdCalculate_Click()
Dim i As Integer
Dim average As String

'Set counter to 0
counter = 0

'Set sum to 0
sum = 0

'Count number of text boxes that have values
'in them and sum them. If any text box has no
'value (empty) then the counter excludes that
'box in the final equation
For i = 0 To 4
If txtScores(i) <> "" And Not IsNumeric(txtScores(i)) Then
MsgBox "All values must be numeric!"
Exit Sub
End If
Next i

For i = 0 To 4
If txtScores(i) <> "" Then
sum = sum + txtScores(i)
counter = counter + 1
End If
Next i

'Straight forward math done here.
If counter > 0 Then average = sum / counter

txtAnswer.Text = average
End Sub

Private Sub cmdClear_Click()

'Clear all text boxes.
Dim i As Integer

For i = 0 To 4
txtScores(i).Text = ""
Next i

txtAnswer.Text = ""
End Sub

Private Sub cmdExit_Click()
Set frmAverage = Nothing
Unload Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set frmAverage = Nothing
End Sub

Sub PaintForm3D(frm As Form)
' This Sub draws lines around the Form to make it 3d

' white, upper - horizontal
frm.Line (0, 0)-(frm.ScaleWidth, 0), &HFFFFFF, BF
' white, left - vertical
frm.Line (0, 0)-(0, frm.ScaleHeight), &HFFFFFF, BF
' darkgrey, right - vertical
frm.Line (frm.ScaleWidth - 15, 0)-(frm.ScaleWidth - 15, _
frm.Height), &H808080, BF
' darkgrey, lower - horizontal
frm.Line (0, frm.ScaleHeight - 15)-(frm.ScaleWidth, _
frm.ScaleHeight - 15), &H808080, BF

End Sub

Private Sub Form_Load()
Me.AutoRedraw = True
PaintForm3D Me
End Sub

Bilgisayar Dershanesi Ders Sahibi;
Bilgisayar Dershanesi


Yorum Yapabilmek İçin Üye Girişi Yapmanız Gerekmektedir.