Now we come to the code for the Calculate button and this is where most of the action takes place. It looks like this:
Private Sub cmdCalculate_Click()
'assign marks to variables
MarkA = vsbA.Value
MarkB = vsbB.Value
MarkC = vsbC.Value
'calculate average
Average = (MarkA + MarkB + MarkC) / 3
'display the average mark
lblAverage.Caption = "average is " + Str(Average)
'display the pictures
If MarkA > Average Then
imgA.Picture = LoadPicture("c:\vb\icons\misc\face02.ico")
Else
imgA.Picture = LoadPicture("c:\vb\icons\misc\face01.ico")
End If
If MarkB > Average Then
imgB.Picture = LoadPicture("c:\vb\icons\misc\face02.ico")
Else
imgB.Picture = LoadPicture("c:\vb\icons\misc\face01.ico")
End If
If MarkC > Average Then
imgC.Picture = LoadPicture("c:\vb\icons\misc\face02.ico")
Else
imgC.Picture = LoadPicture("c:\vb\icons\misc\face01.ico")
End If
End Sub