Darwinbots Forum
Code center => Darwinbots Program Source Code => Topic started by: Ulciscor on June 29, 2005, 06:24:32 PM
-
OK I have defined a custom type as:
Type gene
geneNum As Integer
conditionDNA As String
bodyDNA As String
End Type
and an array:
Public genome() As gene
And then when a button is clicked I have:
genePoint = genePoint + 1
With genome(genePoint)
.geneNum = genePoint
.conditionDNA = ""
.bodyDNA = ""
End With
genePoint is an integer with a start value of 0.
The error I get in debug is:
"Object variable or with block variable not set."
What the heck is going on!?
-
Public genome() As gene
Here's the problem, I guess. You have declared the data type for genome, but you haven't instantiated it yet. This means, that genome is a pointer to a gene object, but you haven't created the object.
Try instead
Public genome() As new gene
-
Now it says 'Invalid use of New keyword' lol.
Is it clear what I'm trying to do or should I try and explain? The code is probably pretty crappy lol.
-
Here is the problem, The code you posted Ulcisor WORKS PERFICT.
Post the whole .frm file so I can finaly have a clue where the problem is.
-
Here ya go
-
P. S. make sure this stuff is in a bas file:
Type gene
geneNum As Integer
conditionDNA As String
bodyDNA As String
End Type
and an array:
Public genome() As gene
and that you redim genome() to atleast 1 before you click that button, otherwise you got a non-exsistent array
P. P. S.
Ulcisor, they got the breack button on the error menu for a reason , click it , it will go to the line were the error is. If you still have no clue how that line caused the error go to View > Calls Stack , but you really have to understand the languge well to go through all that code bc calls stack builds up really quickly sometimes.
-
Lol I seem to have sorted it out now sorry. It was doing some crazy stuff before.
-
scratch the bas idea , this should work fine:
Option Explicit
'Set up arrays and variables
Private Type gene
geneNum As Integer
conditionDNA As String
bodyDNA As String
End Type
Private genome() As gene
Private genePoint As Integer
Private Sub Form_Load()
genePoint = 0
ReDim genome(20) ' 20 you like 20 ???
End Sub
Private Sub lblAddNew_Click()
genePoint = genePoint + 1
With genome(genePoint)
.geneNum = genePoint
.conditionDNA = ""
.bodyDNA = ""
End With
End Sub
-
lol you beat me to it.
-
I had to rewrite it to this:
genome(genePoint).geneNum = genePoint
genome(genePoint).conditionDNA = ""
genome(genePoint).bodyDNA = ""
genePoint = genePoint + 1