Solved

an equivlient to a long enum

Posted on 2006-11-26
7
191 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 24

Expert Comment

by:Jeff Certain
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Chaosian
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now