Constant Array

P

Phil

'I'd like to have a public array:

Public aType(202) As String

'and I'd like to assign constant values to it without
having to run a program to assign them; that is, I want
to assign them as constants.
However, this does not work with arrays.
Public Const aType (1) = "dbBoolean"
Public Const aType(dbText) = "dbText"

'I need them in an array because I'm going to use them as
follows:
Debug.Print dbBoolean, aType(dbBoolean)

1 dbBoolean

Since this seems like such a reasonable thing to do with
this enum, I wonder if there might be some other approach.

Thanks for your help.

Phil
 
T

Tim Ferguson

Since this seems like such a reasonable thing to do with
this enum, I wonder if there might be some other approach.

If you really want an enum, then you can do that:

Public Enum tfMyList
tfMyListOne
tfMyListTwo
' etc
End Enum

but if you want to return strings and other objects, then the best bet is
probably a public function

' make it a variant so it can return anything
Public Function MyList(Index as Integer) as Variant

' get the index number
Select Case Index
Case 1
MyList = "dbTemp"
Case 2
MyList = 99.345
Case 3
' variants can return objects too
Set MyList = CreateObject("VBScript.RegExp")

Case Else
MyList = Null

End Select
End Function


There is no DATA statement in VBasic, which is kind of a pity. Another
alternative is to put the values in a table (this is Access, after all) and
call a DLookUp() to get them back. Another possibility would be to put them
in the database properties -- if you use the UserProperties Document, then
the user can use the UI to edit them when the code doesn't work...


All the best


Tim F
 

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