Solved

an equivlient to a long enum

Posted on 2006-11-26
7
201 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET Repostiory Pattern 7 49
VB.net Open Folder in Windows Explorer 3 52
Datagridview column when exported to Excel changes vb.net 1 19
vb.net and creating a class 5 20
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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