VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find average of 3 numbers with data validation and round answer to 2 decimal places.

by Brandon (46 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 30th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Find average of 3 numbers with data validation and round answer to 2 decimal places.

Rate Find average of 3 numbers with data validation and round answer to 2 decimal places.



'label the label with the caption Average, remove all text from
'text boxes.
'enter the following code in the command button control.

Private Sub Command1_Click()
Const Count As Integer = 3
Dim FirstNum, SecondNum, ThirdNum As Integer
Dim Average, Sum As Currency
'validate data
If Text1 = vbNullString Or Text2 = vbNullString Or Text3 = vbNullString Then
    MsgBox "No value entered, please make sure all entries are made", vbExclamation, "Missing Data"
End If
'validate data for numbers only
If Not IsNumeric(Text1) Or Not IsNumeric(Text2) Or Not IsNumeric(Text3) Then
    MsgBox "Invalid entries, please enter numbers only", vbCritical, "Error"
End If
'find average of 3 numbers
FirstNum = Val(Text1)
SecondNum = Val(Text2)
ThirdNum = Val(Text3)
Sum = FirstNum + SecondNum + ThirdNum
Average = Sum / Count
Text4 = Round(Average, 2)
End Sub


Download this snippet    Add to My Saved Code

Find average of 3 numbers with data validation and round answer to 2 decimal places. Comments

No comments have been posted about Find average of 3 numbers with data validation and round answer to 2 decimal places.. Why not be the first to post a comment about Find average of 3 numbers with data validation and round answer to 2 decimal places..

Post your comment

Subject:
Message:
0/1000 characters