Solved

an equivlient to a long enum

Posted on 2006-11-26
7
198 Views
Last Modified: 2010-04-23
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
Comment
Question by:Chaffe
  • 3
  • 3
7 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18016487
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
 
LVL 10

Expert Comment

by:gangwisch
ID: 18017288
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
 

Author Comment

by:Chaffe
ID: 18017513
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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18018982
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
 

Author Comment

by:Chaffe
ID: 18019908
Chaosian, would you still recommend doing a My.Settings.SettingName if I have say a 100 of them or so??  any performance concerns?
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 300 total points
ID: 18019959
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
 

Author Comment

by:Chaffe
ID: 18164294
Thanks Chaosian
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question