Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Constant Arrays?

Status
Not open for further replies.

Donato

Programmer
Joined
Jan 12, 2002
Messages
8
Location
CA
Hi,

I'm trying to create an array as a constant.
Is this possible in VB 6?

Here is a sample of what I am try to do:

Const ServiceType = ["ITEM1", "ITEM2", "ITEM3", "ITEM4", "ITEM5"]

Thanks.
 
Hi Donato,

Did you figure out if this was possible? I have been having the same dilema....

VW....
 
Private ServiceType() as string
Form_Initialize 'or Class_Intitialize
ServiceType = Split("ITEM1,ITEM2,ITEM3,ITEM4,ITEM5",",")
End Sub

In a Sub or Function
.... SUb ....
Static ServiceType() as String
Static blnInit as Boolean
if blnInit = false then
ServiceType = Split("ITEM1,ITEM2,ITEM3,ITEM4,ITEM5",",")
blnInit = True
end if
End Sub

Change if "," can occur in data the substitute "~" or whatever.
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
The best you can do is what JohnYingling is pointing out:
1. Create a string constant with a delimiter
Const ServiceType$ = "ITEM1, ITEM2, ITEM3, ITEM4, ITEM5"

When needing to access the elements you could use the Split function to create an array out of the string:

Dim myArray() As String

myArray = Split(ServiceType, ",")
Debug.Print myArray(2) 'returns ITEM3



Also as JohnYingling pointed out, you need to select a delimter that isn't already used in one of the items. A Tab delimeter may be good to use:

Const ServiceType$ = "ITEM1" & vbTab & "ITEM2" & vbTab & "ITEM3" & vbTab & "ITEM4"

Dim myArray() As String

myArray = Split(ServiceType, ",")
Debug.Print myArray(2) 'returns ITEM3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top