Have a look to the project and please correct me.

mozaharul

Active Member
Licensed User
Hi,
In the attached project (with database), Table1 represents individual house hold and head name. Clicking a house hold will show the Date of birth (dob) of all members of that house hold in Table2.

What I want:
Calculation of individual member’s age and to keep those in an array variable, so could be use later in the program.

What I did:
Declared in Global sub an array variable agecal (0) in line-3
Redefined it with “RowCount” of table2 in line-26
And tried to calculate individual’s age in line-29
But doesn’t calculate any thing !

Please help.


Regards
 

Erel

Administrator
Staff member
Licensed User
You should redefine the array with:
B4X:
Dim agecal(rc)
The complete sub should be:
B4X:
Sub Table1_SelectionChanged (ColName, Row)
    If table1.SelectedRow >=0 Then
        i=table1.SelectedRow 
        txthpidselect.Text=table1.Cell("HPID",i)
        cmd.CommandText="select dob from member where hpid="&table1.Cell("HPID",i)
        cmd.ExecuteTable("table2",0)
        rc=table2.RowCount
        Dim agecal(rc) ' array variable "agecal" is redefined here.
        For i=0 To table2.RowCount-1
            agecal(i)= Int(((calendar1.Value-DateParse(table2.Cell("dob",i)))/cTicksPerDay)/365.25)
        Next
    End If
End Sub
BTW, you can call DateFormat under App_Start instead of calling it each time.
 
Top