Link to home
Start Free TrialLog in
Avatar of Chaffe
ChaffeFlag for Afghanistan

asked on

an equivlient to a long enum

Greetings,  I utilize enumerations in many functions throughout my application to avoid typos and take advantage of the intellicense.
---------------------------
    Public Enum Position
        First
        Last
    End Enum

        Public Sub GetLocation(ByVal Pos As RCPosition)
        End Sub
---------------------------
Now, using enums is ver handy if your items are short (ie: First, Last, etc...) but how about if if I have longer variables?  say I want to store Url Paths.  I've been storing such items as constants in their own class.  ie:
-----------------------------
        Public Class JSPaths
            Public Const Path1 As String = "very long url here"
            Public Const Path2 As String = "another very long url here"
        End Class
----------------------------
with such set up, I obviously don't have the advantages that I have with enums.  Isn't there a way for me to store long variables in a similar fashion to an enumeration?  would having a strucutre be my solution?  Thanks.
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

I'd put these in your project settings. Then you can refer to them from My.Settings.SettingName from anywhere in that project.
Caveat: this only works with VS2005.
Avatar of gangwisch
gangwisch

yes the best way to implement this is through an arraylist
dim urls as new arraylist
urls.add("very long url here)
urls.add("another very long url here)
therefore
path1=urls(0)
path2=urls(1)

so to go through all of the urls

for each strurl as string in urls
'strurl will currently equal the url
next

good luck
Avatar of Chaffe

ASKER

Thanks for the suggestion guys.  just an FYI, I'm not building these variables dynamically or anything.. they're just a bunch of constants that I need to grab and use in different locations in my project.

In both of these suggestions, can I take advantage of the intellicense like we do in the enums?  Thanks.
Intellisense? In the case of the settings, yes. In the case of the arraylist, no.

As an aside, I'd recommend System.Collections.Generic.List(of String) in place of an arraylist. The new generic collections are type-safe (no more casting), improve performance, and are easier to use.
Avatar of Chaffe

ASKER

Chaosian, would you still recommend doing a My.Settings.SettingName if I have say a 100 of them or so??  any performance concerns?
ASKER CERTIFIED SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chaffe

ASKER

Thanks Chaosian