Attribute VB_Name = "Module3" ' Function Name: NumOfHomozygotes() ' Parameters Byval: row, leftColumn, rightColumn, lociNum ' Return type: Integer ' Description: Searches through a single locus for homozygous individuals. Public Function NumOfHomozygotes(ByVal row, ByVal leftColumn, ByVal rightColumn, ByVal lociNum) As Integer ' [DECLARE VARIABLES] Dim colony As Variant, allele1 As Variant, allele2 As Variant Dim alleleNum As Integer, colonyColumn As Integer, alleleLimit As Integer ' [INITIALISE VARIABLES] colonyColumn = 1 colony = ActiveSheet.Cells(row, colonyColumn).Value ' Finds colony name. alleleNum = 0 alleleLimit = 2 Do allele1 = ActiveSheet.Cells(row, leftColumn).Value ' Stores the value of the first allele at a locus. allele2 = ActiveSheet.Cells(row, rightColumn).Value ' Stores the value of the second allele at a locus. If (SameAllele(allele1, allele2)) Then If AddToQueenArray(lociNum, (alleleNum + 1), allele1) Then alleleNum = alleleNum + 1 End If NumOfHomozygotes = alleleNum If (alleleNum = alleleLimit) Then GoTo endloop End If row = row + 1 ' Iterates through the sampled workers of the colony. Loop While (Module2.CheckColony(row, colony, colonyColumn)) 'Ensures that only one colony is analysed at a time. endloop: ' Do nothing. End Function ' Function Name: SameAllele() ' Parameters Byval: allele1, allele2 ' Return type: Boolean ' Description: Compares two alleles. Private Function SameAllele(ByVal allele1, ByVal allele2) As Boolean ' [DECLARE VARIABLES] Dim nullAllele As String ' [INITIALISE VARIABLES] nullAllele = "." ' This corresponds to an unknown result placed in the data set by the user. If ((allele1 = allele2) And (allele1 <> nullAllele)) Then SameAllele = True Else SameAllele = False End If End Function ' Function Name: AddToQueenArray() ' Parameters Byval: lociNum, alleleNum, allele ' Return type: Boolean ' Description: Adds an allele to the Queen's genotype (if required). Private Function AddToQueenArray(ByVal lociNum, ByVal alleleNum, ByVal allele) As Boolean ' [DECLARE VARIABLES] Dim firstAllele As Integer ' [INITIALISE VARIABLES] firstAllele = 1 ' If statement tests whether the current allele has already been added to the Queen's genotype. If (queenArray(lociNum, firstAllele) = allele) Then AddToQueenArray = False Else queenArray(lociNum, alleleNum) = allele AddToQueenArray = True End If End Function