Attribute VB_Name = "Module4" ' Function Name: IsHomozygousQueen() ' Parameters Byval: row, leftColumn, rightColumn, lociNum, colonyNum ' Return type: Boolean ' Description: Determines if Queen is homozygous at a particular locus. Public Function IsHomozygousQueen(ByVal row, ByVal leftColumn, ByVal rightColumn, ByVal colonyNum) As Boolean ' [DECLARE VARIABLES] Dim testAllele As Variant, colony As Variant, testAlleleArray() As Variant Dim colonyColumn As Integer, counter As Integer, column As Integer, testRow As Integer Dim nullAllele As String Dim notTested As Boolean, homozygous As Boolean ' [INITIALISE VARIABLES] colonyColumn = 1 colony = ActiveSheet.Cells(row, colonyColumn).Value nullAllele = "." ReDim testAlleleArray(1) For column = leftColumn To rightColumn For testRow = row To endColony(colonyNum) ' Row being tested. notTested = True testAllele = ActiveSheet.Cells(testRow, column).Value If (testAllele <> nullAllele) Then For counter = 1 To UBound(testAlleleArray) ' Determine whether allele has already been tested. If (testAllele = testAlleleArray(counter)) Then notTested = False Exit For End If Next counter If (notTested) Then testAlleleArray(UBound(testAlleleArray)) = testAllele ' ReDim Preserve statement increases the size of the array, whilst preserving the value of each element of the array. ReDim Preserve testAlleleArray(UBound(testAlleleArray) + 1) ' array has one extra space. Ie: Upper bound of array is empty. homozygous = IsPresent(row, colony, testAllele, leftColumn, rightColumn) End If End If If (homozygous) Then IsHomozygousQueen = True GoTo endloop ' Jump to the statement "endloop:" Else IsHomozygousQueen = False End If Next testRow Next column endloop: End Function ' Function Name: IsPresent() ' Parameters Byval: row, colony, testAllele, leftColumn, rightColumn ' Return type: Boolean ' Description: Scans through data set with a particular cell value, and determines ' if a allele is present in every worker. Private Function IsPresent(ByVal row, ByVal colony, ByVal testAllele, ByVal leftColumn, ByVal rightColumn) As Boolean ' [DECLARE VARIABLES] Dim allele1 As Variant, allele2 As Variant Dim nullAllele As String Dim colonyColumn As Integer ' [INITIALISE VARIABLES] colonyColumn = 1 ' Refers to column A. Ie: the column where the colony names are entered by the user. nullAllele = "." ' Corresponds to a dot(.) in the original data set. IsPresent = True ' A value of true means that an allele is present in every worker (of a single colony) sampled. Do allele1 = ActiveSheet.Cells(row, leftColumn).Value allele2 = ActiveSheet.Cells(row, rightColumn).Value If (allele1 = nullAllele) And (allele2 = nullAllele) Then row = row + 1 ' Skip a null result. Else If ((testAllele = allele1) Or (testAllele = allele2)) Then IsPresent = True row = row + 1 Else IsPresent = False End If End If Loop While (IsPresent And Module2.CheckColony(row, colony, colonyColumn)) ' Requires both conditions to be true. End Function