app that open a dat file with info.

frostwhitedc4
04-28-2003, 11:15 PM
im suppose to make an app that opens this file with names
name, sex (f/m/), and age within it and display the average date and number of males and females. this is the code i have for the display button

Private Sub cmdDisplay_Click()
Dim strAverage As String, intItem As Integer
Open "G:\Visual Basic 6 Student Files\Tut07\lc2.dat" For Input As #1
Do While Not EOF(1)
Input #1, strAverage, intItem




Select Case strAverage
Case "male"
lblTotalMale.Caption = Val(lblTotalMale.Caption)
Case "female"
lblTotalFemale.Caption = Val(lblTotalFemale.Caption)

End Select
Loop
Close #1
End Sub


when i click that display button, the lblTotalMale.caption and lblTotalFemale.caption would display 0. can u help me?

Irotallic
04-29-2003, 01:36 AM
I am not quitte sure if this solves the problem, but your average is a string. Shouldn't that be a long or something? And second you'll never use 'strAverage' and 'intItem', you directly start with 'lblTotalMale.Caption = Val(lblTotalMale.Caption)'. I guess you firstly have to fill the label with any value of your variabeles.

Hope it helps.

Garmour
04-29-2003, 02:31 AM
It's a bit difficult to understand your question...average date ??? do you mean average age ?
From looking at your code I'd guess you were trying to count the number of males and females.
first, your input statement doesn't match what you say is in the file.
You said name, sex, age but you are only grabbing two things from the file strAverage, intItem. What are they ?
You need to know exactly what is in the file before writing your input statement.

Assuming the file contains name, sex, age as you first stated then your input statement should be something like.

input #1, sName, sSex, iAge


If that matches your fileformat you would then need to count the number of males and females.
Your select case statement is almost correct but I'll change it a bit to total the number of each sex

select case sSex
case "male"
lblTotalMale.caption = val(lblTotalMale.caption) + 1
case "female"
lblTotalFemale.caption = val(lblTotalFemale.caption) + 1
end select


To work out the average age you would need to keep a running total of the iAge variable somewhere and also a count of how many ages there are (ie, lbltotalmale + lbltotalfemale).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum