Author Topic: Help!  (Read 4508 times)

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
Help!
« 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!?
« Last Edit: June 29, 2005, 06:25:56 PM by Ulciscor »
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline Carlo

  • Bot Destroyer
  • ***
  • Posts: 122
    • View Profile
Help!
« Reply #1 on: June 29, 2005, 06:44:17 PM »
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

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
Help!
« Reply #2 on: June 29, 2005, 06:46:00 PM »
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.
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Help!
« Reply #3 on: June 29, 2005, 07:41:01 PM »
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.

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
Help!
« Reply #4 on: June 29, 2005, 07:45:15 PM »
Here ya go
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Help!
« Reply #5 on: June 29, 2005, 07:47:15 PM »
P. S. make sure this stuff is in a bas file:
Quote
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.

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
Help!
« Reply #6 on: June 29, 2005, 07:49:17 PM »
Lol I seem to have sorted it out now sorry. It was doing some crazy stuff before.
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Help!
« Reply #7 on: June 29, 2005, 07:50:37 PM »
scratch the bas idea , this should work fine:

Quote
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

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Help!
« Reply #8 on: June 29, 2005, 07:51:28 PM »
lol you beat me to it.

Offline Ulciscor

  • Bot Destroyer
  • ***
  • Posts: 401
    • View Profile
Help!
« Reply #9 on: June 29, 2005, 07:53:02 PM »
I had to rewrite it to this:

genome(genePoint).geneNum = genePoint
genome(genePoint).conditionDNA = ""
genome(genePoint).bodyDNA = ""
genePoint = genePoint + 1
:D Ulciscor :D

I used to be indecisive, but now I'm not so sure.