' ' 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 ' Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir. 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: ' Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir. style="color: #0000BB">Nice 3D Effect, try it!
'Email: Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir. .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