VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Calculate and show the Average result (in percent) and add to a ListBox

by Patrick Lockefeer (VI) (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 8th November 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Calculate and show the Average result (in percent) and add to a ListBox

API Declarations


Dim Attempts As Integer
Dim Hits As Integer

Controls :

2 TextBoxes Name : Text1 & Text2
Commandbutton Name : Command1
ListBox Name : List1


Rate Calculate and show the Average result (in percent) and add to a ListBox



'European date : 11/8/2005
'Please see my other Snippets on page 607,609 and 610


Private Sub Command1_Click()

Attempts = Val(Text1): Hits = Val(Text2)

'Validate Hits > Attempts
If Hits > Attempts Then
MsgBox "Hits must be lower than Attempts"
Command1.Caption = " No result "
Else
'Calculate percent
Average = Format(Hits / Attempts, "percent")
'Show result (average percent) on the Commandbutton
Command1.Caption = "Average : " & Average
'Add result to Listbox
List1.AddItem Attempts & " - " & Hits & "  = " & Average

End If

End Sub



Download this snippet    Add to My Saved Code

Calculate and show the Average result (in percent) and add to a ListBox Comments

No comments have been posted about Calculate and show the Average result (in percent) and add to a ListBox. Why not be the first to post a comment about Calculate and show the Average result (in percent) and add to a ListBox.

Post your comment

Subject:
Message:
0/1000 characters