|
-
Nov 16th, 2000, 11:59 PM
#1
Thread Starter
New Member
Hi, Im a student taking my first class in VB, I have a assigment that I am stuck on. They want us to create a application that uses a display button that reads a dat file and displays the information into label controls on the form. Displaying total males, females, and the average age of females and males. I can get the display button to display the total males and total females but I'm having problems figuring out the average age everything I try dosen't work. Here is the dat file and what I have. Any help would be great!
Dat File
"Mary","Female",21
"Terri","Female",18
"Jim","Male",39
"Paula","Female",53
"George","Male",45
"Fred","Male",25
Open "A:\1c2.dat" For Input As #1
Do While Not EOF(1)
Input #1, pstrName, pstrGender, psngAge
Select Case pstrGender
Case "Male"
lblScore(0).Caption =Val(lblScore(0).Caption) + 1
Case "Female"
lblScore(2).Caption =Val(lblScore(2).Caption) + 1 End Select
Loop
Close #1
End Sub
-
Nov 17th, 2000, 07:06 AM
#2
Lively Member
To get the average of a group of numbers, you need to Divide the sum of the numbers by the count of actual numbers.
In your Routine, Declare two integer variables, MaleCount and FemaleCount
Code:
Dim MaleSum as integer
Dim MaleCount as integer
Dim FemaleSum as integer
Dim FemaleCount as integer
'Your other declarations
Open "A:\1c2.dat" For Input As #1
Do While Not EOF(1)
Input #1, pstrName, pstrGender, psngAge
Select Case pstrGender
Case "Male"
MaleSum = MaleSum + psngAge
lblScore(0).Caption = Trim(Str(MaleSum))
MaleCount = MaleCount + 1
Case "Female"
FemaleSum = FemaleSum + psngAge
lblScore(2).Caption = Trim(Str(FemaleSum))
FemaleCount = FemaleCount + 1
End Select
Loop
Close #1
lblMaleAv.caption = Trim(Str(MaleSum \ MaleCount)
lblFemaleAv.caption = Trim(Str(FemaleSum \ FemaleCount)
End Sub
Hope this is of assistance
Adrian
-
Nov 17th, 2000, 10:36 PM
#3
Thread Starter
New Member
Thanks AdrianH I appreciate your help very much, Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|