Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

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.
0
Chaffe
Asked:
Chaffe
  • 3
  • 3
1 Solution
 
Jeff CertainCommented:
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.
0
 
gangwischCommented:
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
0
 
ChaffeAuthor Commented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jeff CertainCommented:
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.
0
 
ChaffeAuthor Commented:
Chaosian, would you still recommend doing a My.Settings.SettingName if I have say a 100 of them or so??  any performance concerns?
0
 
Jeff CertainCommented:
Well, they're stored as XML in your app config file -- the properties page in VS is just a nice UI for dealing with them.

Not sure what the performance is like with a whole bunch of them. However, if all you need to do is hit your local file system, there shouldn't be a huge performance hit. It won't be nearly as fast as using constants (since they're injected directly into your code at compile time), but it shouldn't be noticeable unless you're hitting them very often.
0
 
ChaffeAuthor Commented:
Thanks Chaosian
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now