array problem

J

Jean-Yves Simon

Hi all,

I have a little problem with an array. Here is what I am doing


Function foo(N1 As String) As String
Dim MyResult As String
Dim S1(64) As String
Dim S2(64) As String
Dim S3(64) As String
Dim S4(64) As String
Dim S5(64) As String
Dim S6(64) As String
Dim S7(64) As String
Dim S8(64) As String

'init array

S1(0) = "1110"
S1(2) = "0100"
.... and so on

When I do that, I have an error
"compile error"
invalid outside procedure"

I clicked on the help button to try to understand but I dont
get it why I have this error. Is this not a proper way to init
an array ?
 
T

Tushar Mehta

What line does the VBE point to when it pops up with the error message?
The message typically means that you have some kind of unacceptable
statement outside of the scope of any sub/function.

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
J

Jean-Yves Simon

Tushar said:
What line does the VBE point to when it pops up with the error message?
The message typically means that you have some kind of unacceptable
statement outside of the scope of any sub/function.
Hi,

Thanks for replying. The error is on the first line where I init
the array ie:

S1(0) = "1110"

Thanks and regards
Jean-Yves.

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

--
--
Jean-Yves SIMON E-mail : (e-mail address removed)

==================================================================
Jean-Yves Simon TEXAS INSTRUMENTS FRANCE
WTBU Platform and IC Development Tel : +33 (0)4.93.22.29.60
Cel : +33 (0)6.78.41.67.82
mailto:[email protected] Fax : +33 (0)4.93.22.22.75
==================================================================
 
B

Bill Plenge

Jean-Yves Simon said:
Hi,

Thanks for replying. The error is on the first line where I init
the array ie:

S1(0) = "1110"

Thanks and regards
Jean-Yves.

Are you certain the sample code you posted is a correct recreation of the
problem? If I cut and past it into Excel XP or VB6, once I add an end
function it runs just fine using a test call of Result$ = foo("Test"). Can
you post the actual code that has the problem? From the error you're
describing it sounds as if the code assigning the values isn't inside a
procedure (Sub or Function.)

Best,
Bill
 
H

Harlan Grove

Jean-Yves Simon said:
. . . The error is on the first line where I init
the array ie:

S1(0) = "1110"
....

Do you have an 'Option Base 1' at the top of the module?
 
D

Dave Peterson

I got a "subscript out of range" error when I did that.

(But I don't have a better guess.)
 
J

Jean-Yves Simon

Dave said:
I got a "subscript out of range" error when I did that.
(But I don't have a better guess.)

Hi all,

Finally after all your posts, I decided to delete and rewrite
everything. And I will never know why, but this time it worked
fine.

Thanks you for everything.

Thanks and best regards.
 
D

Dave Peterson

I'm not sure if this would have helped, but you may want to add it to your
arsenal of tools.

It's Rob Bovey's codecleaner program.

You can find it at:
http://www.appspro.com/

It exports your modules, removes the modules and then reimports them. The act
of reimporting them can remove a bunch of detritus that builds up through lots
of changes/recompiles.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top