Problems with array in module (Access '97)

  • Thread starter Nick via AccessMonster.com
  • Start date
N

Nick via AccessMonster.com

Hi,

I'm having some troubles using a string array in a module in VBA. I can
dimension the string array but am unable to set the variables equal to a
constant within the module (Really needs to be in the module). Actual code
(all two lines of it) is near the end.

When I try to set strStep1(1) = "Description" by using 'Set' or 'Let'
it gives an error (Invalid outside procedure), and when I try using 'Const'
declaration, an error is generated when the program gets to the
parenthesis.

Public strStep1(10) As String

Set strStep1(1) = "Description" 'Invalid outside procedure
-or-
Public Const strStep(1) as string = "Description" 'Gets to '(' and expects
'As' or '='

Any help would be appreciated, post back if clarification is needed.

Thanks,

Nick
 
M

Marshall Barton

Nick said:
I'm having some troubles using a string array in a module in VBA. I can
dimension the string array but am unable to set the variables equal to a
constant within the module (Really needs to be in the module). Actual code
(all two lines of it) is near the end.

When I try to set strStep1(1) = "Description" by using 'Set' or 'Let'
it gives an error (Invalid outside procedure), and when I try using 'Const'
declaration, an error is generated when the program gets to the
parenthesis.

Public strStep1(10) As String

Set strStep1(1) = "Description" 'Invalid outside procedure
-or-
Public Const strStep(1) as string = "Description" 'Gets to '(' and expects
'As' or '='


In this case, the error message means exactly what it says.

Move the array initialization to a procedure that you can
call at the appropriate time.

Don't use Set, it's for objects. Either use Let (archaric)
or nothing (standard):

Public Sub InitArray()
strStep1(1) = "Description"
End Sub
 
N

Nick via AccessMonster.com

Thanks Marshall, I had overlooked the obvious... Thanks for steering me
back. I tend to overcomplicate my programs if I'm not careful.

Thanks again,

Nick
 

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