Attribute VB_Name = "Module2" ' Subroutine Name: FindColony() ' Parameters Byval: row ' Description: Determines name, number and size of each colony in the data set. Public Sub FindColony(ByVal row) ' [DECLARE VARIABLES] Dim column As Integer Dim colony As Variant Dim emptyCell As String ' [INITIALISE VARAIBLES] column = 1 emptyCell = "" ' Represents an cell is empty. ReDim colonyArray(1) ' Both ReDim statements allow EzyMate to increase the size of the array ReDim endColony(1) ' as it requires. This saves memory. colony = ActiveSheet.Cells(row, column).Value ' Retrieves the current colony name. colonyArray(1) = colony ' Stores first colony name into the colonyArray. row = row + 1 Do If ((ActiveSheet.Cells(row, column).Value) = colony) Then ' Written for clarity purposes. ' Do nothing. Else ' Executes if the colony name changes. endColony(UBound(endColony)) = row - 1 ReDim Preserve endColony(UBound(endColony) + 1) ReDim Preserve colonyArray(UBound(colonyArray) + 1) ' Increases the array size. colony = ActiveSheet.Cells(row, column).Value colonyArray(UBound(colonyArray)) = colony End If row = row + 1 Loop While ((ActiveSheet.Cells(row, column).Value) <> emptyCell) endColony(UBound(endColony)) = row - 1 End Sub ' Function Name: FindLoci() ' Parameters Byval: GetStartAllele ' Return type: Integer ' Description: Determines the name and number of loci in the data set. Public Function FindLoci(ByVal GetStartAllele) As Integer ' [DECLARE VARIABLES] Dim startRow As Integer Dim emptyCell As String Dim count As Integer ' [INITIALISE VARAIBLES] ReDim lociArray(1) startRow = 1 emptyCell = "" If (GetStartAllele <> -1) Then ' minus 1 represents program termination ActiveSheet.Cells(startRow, GetStartAllele).Select ' Selects the starting column defined by the user. lociArray(1) = ActiveCell.Value ' Stores the name of the first locus. ActiveCell.Offset(0, 2).Select ' Selects the cell two columns across from the current cell. Do While (ActiveCell.Value <> emptyCell) ReDim Preserve lociArray(UBound(lociArray) + 1) lociArray(UBound(lociArray)) = ActiveCell.Value ActiveCell.Offset(0, 2).Select Loop FindLoci = GetStartAllele ' Assigns the value stored in GetStartAllele to FindLoci. ' The value stored in FindLoci is then returned. Else FindLoci = -1 ' minus 1 represents program termination End If End Function ' Function Name: GetStartAllele() ' Return type: Integer ' Description: Retrieves the start column for the data analysis. This enables the user to add ' extra columns for important information before the data to be used by EzyMate. Public Function GetStartAllele() As Integer ' [DECLARE VARIABLES] Dim minVal As Integer Dim userResponse As Variant Dim message As String, message1 As String, message2 As String Dim validEntry As Boolean ' [INITIALISE VARAIBLES] ' message displayed to user. message1 = "Please enter the column number of the first allele in the data set." message2 = " " & vbCrLf & "For Example: If the first allele of the data set is in Column D, then enter then number 4." message = message1 & message2 minVal = 2 validEntry = False Do userResponse = InputBox(message, "User Input Required") If IsNumeric(userResponse) Then If (userResponse >= minVal) Then validEntry = True GetStartAllele = Int(userResponse) Else message = "Previous response is invalid. Please ensure that the alleles of the data set do not start before column 2." message = message & vbCrLf & vbCrLf message = message & message1 & message2 End If ElseIf (userResponse = "") Then GetStartAllele = -1 ' minus 1 respresents program termination. MsgBox ("EzyMate exiting...") Else ' Ie: value entered is not an integer. message = "Previous response is invalid. Input must be an integer." validEntry = False ' Allows user to re-renter a response. End If Loop Until (validEntry Or (GetStartAllele = -1)) ' Continues to loop until the user enters a valid input. End Function ' Function Name: CheckColony() ' Parameters Byval: row, colony, colonyColumn ' Return type: Boolean ' Description: Limits the analysis process to one colony at a time, by returning ' false if the colony changes. Public Function CheckColony(ByVal row, ByVal colony, ByVal colonyColumn) As Boolean If ((ActiveSheet.Cells(row, colonyColumn).Value) = colony) Then CheckColony = True Else CheckColony = False End If End Function ' Function Name: EvenNumOfLoci() ' Parameters Byval: testColumn ' Return type: Boolean ' Description: Ensures that each locus has two alleles. Public Function EvenNumOfLoci(ByVal testColumn) As Boolean ' [DECLARE VARIABLES] Dim startRow As Integer, numOfAlleles As Integer, startColumn As Integer Dim emptyCell As String ' [INITIALISE VARAIBLES] startRow = 1 emptyCell = "" numOfAlleles = 1 startColumn = testColumn Do While (ActiveSheet.Cells(startRow, testColumn + 1).Value <> emptyCell) numOfAlleles = numOfAlleles + 1 testColumn = testColumn + 1 Loop If ((numOfAlleles Mod 2) <> 0) Then ' ie: an even number of alleles is not found. EvenNumOfLoci = False MsgBox ("The data set to be analysed does not contain two alleles per locus. EzyMate exiting...") Else EvenNumOfLoci = True End If Call ScanInput(numOfAlleles, startColumn) End Function ' Subroutine Name: ScanInput() ' Parameters Byval: numOfAlleles, startColumn ' Description: Replaces any blank cells with a dot. Private Sub ScanInput(ByVal numOfAlleles, ByVal startColumn) ' [DECLARE VARIABLES] Dim startRow As Integer Dim endColumn As Integer, endRow As Integer ' [INITIALISE VARAIBLES] startRow = 2 endColumn = (numOfAlleles - 1) + startColumn endRow = endColony(UBound(endColony)) Range(Cells(startRow, startColumn), Cells(endRow, endColumn)).Select Selection.Replace What:="", Replacement:=".", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False End Sub