Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Novice VBA question (error on previous reply)

Author: Andrew Wagner

Date: 08:56:44 04/07/04

Go up one level in this thread


On April 07, 2004 at 11:39:27, S J J wrote:

>On April 07, 2004 at 11:35:56, S J J wrote:
>
>>On April 07, 2004 at 11:05:48, Andrew Wagner wrote:
>>
>>>On April 07, 2004 at 10:50:17, S J J wrote:
>>>
>>>>  I've been writing a program using Visual Basic.   The pieces are
>>>>being stored in an Array.   When the pieces are moved within the
>>>>subroutine which the Array was created in,  all the pieces move
>>>>correctly.   However, when another subroutine is asked to work
>>>>on the Array, I get the message "Compile error: Sub or Function not defined".
>>>>   Are there any ideas as to what is causing the problem or what can be done
>>>>to fix it?
>>>>
>>>>Thanks,
>>>>Steve
>>>
>>>
>>>Sounds to me like a scope problem. You need to make the array global, or at
>>>least module-level for other procedures to be able to work on it. Hope that
>>>helps. Andrew
>
>Thanks Andrew.   I currently creating the Array in the following command:
>
>Sub WhiteMoveArray()
>Dim MoveArray(1 To 10000, 1 To 100)
>
>
>
>   Any ideas as to how to fix it?
>Regards,
>Steve

Argh. I don't have VB 6 installed anymore, and it's amazing how fast you forget
what it looks like. At any rate, You should have something like this:

Sub Main()
.
.
.
End Sub

Sub WhiteMoveArray()
Dim MoveArray(1 To 10000, 1 To 100)
.
.
.
End Sub

Sub SomeOtherSubRoutine()
MoveArray(1) = blah  'This won't work as you have it now.
.
.
.
End Sub




What you want is this:

Dim MoveArray(1 To 10000, 1 To 100)
Sub Main()
.
.
.
End Sub

Sub WhiteMoveArray()
.
.
.
End Sub

Sub SomeOtherSubRoutine()
MoveArray(1) = blah  'Now this should work. In fact, MoveArray() should
                     'now be accessible to any Sub/Function defined on
                     'this form.
.
.
.
End Sub


Hope that helps! Andrew



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.