Basically I have a piece of code (5 lines commented out toward the end) that runs fine as part of the macro, however I wanted to use the exact same piece of code (only changing one number to a variable) run as a separate function, to make the code look tidier. However when I run that code as a separate function being called I get the error message. "Sub or function not defined."
To see what the program is supposed to do uncomment the block starting with Dim Phenotype... and comment the the line Result(0).
(The last few lines are the important bit, the rest are just declarations)
Sub Basic_example()
'Declarations
'parameters
GeneTable = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", "")
Const Chromolen = 5
Const CrossRate = 0.7
Const MutRate = 0.01
Const poolSize = 40
Const Solution = 42
'others
Dim i As Integer
Dim k As Integer
Dim Pool(poolSize, Chromolen) As Integer
Dim Fitness(poolSize) As Double
Dim GeneNumber As Integer: GeneNumber = UBound(GeneTable)
'fill with random population
For i = 0 To poolSize
For k = 0 To Chromolen
Pool(i, k) = Int(Rnd() * GeneNumber)
Next
Next
'Dim Phenotype As String: Phenotype = vbNullString
'For y = 0 To Chromolen
'Phenotype = Phenotype & GeneTable(Pool(0, y))
'Next
'MsgBox Phenotype
Result (0)
End Sub
Function Result(x)
Dim Phenotype As String: Phenotype = vbNullString
For y = 0 To Chromolen
Phenotype = Phenotype & GeneTable(Pool(x, y))
Next
MsgBox Phenotype
End Function
Bookmarks