by Brandon (46 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 4th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
A program to read numberical input from a text file and prints the sum, the average, the largest and the smallest number in the input file.
API Declarations
Private Sum As Variant
Private Number As Variant
Private Average As Variant
Private MaxNum As Long
Private MinNum As Long
'Before coding this program you should create a file called test.txt and
'place it in My Documents folder on your local hard drive.
Private Sub Command1_Click()
'open file
Open "c:\My Documents\test.txt" For Input As #1
Sum = 0 'initialize
CountNum = 0
MaxNum = -900000000
MinNum = 900000000
Do While Not EOF(1)
Input #1, Number
If Number > MaxNum Then
MaxNum = Number
Else
MaxNum = MaxNum
End If
If Number < MinNum Then
MinNum = Number
Else
MinNum = MinNum
End If
Sum = Sum + Number
CountNum = CountNum + 1
Loop
Average = Sum / CountNum
'output and print to form
Form1.Print "The sum of the numbers in this input file is " & Sum
Form1.Print "The average of the numbers in this input file is " & Round(Average, 2)
Form1.Print "The largest number in this input file is " & MaxNum
Form1.Print "The smallest number in this input file is " & MinNum
Close #1 'close input file
Command1.Enabled = False 'disenable command button
End Sub
Private Sub Form_Load()
Command1.Default = True 'allows you to use enter key
End Sub
No comments have been posted about A program to read numberical input from a text file and prints the sum, the average, the largest an. Why not be the first to post a comment about A program to read numberical input from a text file and prints the sum, the average, the largest an.