|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Organizing Constants for Easier MaintenancePublic Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" Public Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" Public Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" Public Const SCALE_0132DETLS = "Detl 1/32""=1'-0""" Public Const SCALE_0116DETLS = "Detl 1/16""=1'-0""" Public Const SCALE_0332DETLS = "Detl 3/32""=1'-0""" Public Const SCALE_0110PLANS = "Plan 1""=10'" Public Const SCALE_0120PLANS = "Plan 1""=20'" Public Const SCALE_0130PLANS = "Plan 1""=30'" Public Const SCALE_0105DETLS_METRIC = "Met Detl 1:5" Public Const SCALE_0110DETLS_METRIC = "Met Detl 1:10" Public Const SCALE_0150PLANS_METRIC = "Met Plan 1:50" Public Const SCALE_0175PLANS_METRIC = "Met Plan 1:75" In my program, I frequently need to compare a variable to these constants, such as: Select Case curScale 'Imperial Architectural and Civil Plan Scales Case SCALE_0132PLANS, SCALE_0116PLANS, SCALE_0332PLANS, SCALE_0108PLANS, SCALE_0104PLANS, _ SCALE_0308PLANS, SCALE_0110PLANS, SCALE_0120PLANS, SCALE_0130PLANS, SCALE_0140PLANS, _ SCALE_0150PLANS, SCALE_0160PLANS, SCALE_0180PLANS, SCALE_01100PLANS, SCALE_01200PLANS textStyle = curScale + " Callouts" 'Imperial Architectural Detail Scales Case SCALE_0132DETLS, SCALE_0116DETLS, SCALE_0108DETLS, SCALE_0104DETLS, SCALE_0308DETLS, _ SCALE_0102DETLS, SCALE_0304DETLS, SCALE_0100DETLS, SCALE_0112DETLS, SCALE_0300DETLS textStyle = "Detl Callouts" 'Metric Plan Scales Case SCALE_01200PLANS_METRIC, SCALE_01100PLANS_METRIC, _ SCALE_0175PLANS_METRIC, SCALE_0150PLANS_METRIC, SCALE_0125DETLS_METRIC textStyle = curScale + " Callouts" 'Metric Detail Scales Case SCALE_0125DETLS_METRIC, SCALE_0120DETLS_METRIC, SCALE_0116DETLS_METRIC, _ SCALE_0110DETLS_METRIC, SCALE_0105DETLS_METRIC textStyle = "Detl Callouts" Case Else End Select Is there an easier-to-maintain, or more readable, or more elegant way to do this? Can I group the constants like: Public something ImperialScales Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" End something and then do something like: Select Case curScale Case isAMemberOf (ImperialScales) textStyle = curScale + " Callouts" Case isAMemberOf (MetricScales) ... End select TIA for any help and suggestions. -------------------------------------------------------- The impossible just takes a little longer Patrick Pirtle wrote:
> Select Case curScale First off, I noticed in my OP, my Select Case statement> Case isAMemberOf (ImperialScales) > textStyle = curScale + " Callouts" > Case isAMemberOf (MetricScales) > ... > End select got screwed up. Sorry 'bout that. So, just searching some more online, I've found the "Collection" and "Dictionary" objects. I suppose I could do: Dim ImperialScales Dim MetricScales Set ImperialScales = CreateObject(Scripting.Dictionary) ImperialScales.add "SCALE_0132PLANS", "Plan 1/32""=1'-0""" ImperialScales.add "SCALE_0116PLANS", "Plan 1/16""=1'-0""" ImperialScales.add "SCALE_0332PLANS", "Plan 3/32""=1'-0""" Set MetricScales = CreateObject(Scripting.Dictionary) MetricScales.add "SCALE_0105DETLS_METRIC", "Met Detl 1:5" MetricScales.add "SCALE_0110DETLS_METRIC", "Met Detl 1:10" MetricScales.add "SCALE_0150PLANS_METRIC", "Met Plan 1:50" Then, in my Select Sase statement, I could do something like: Select Case curScale 'Imperial Architectural and Civil Plan Scales Case ImperialScales.Exists (curScale) ...do something... Case MetricScales.Exists (curScale) ...do something else Case Else End Select I'll go try this. However, I would welcome any suggestions for better ways to do this. -------------------------------------------------------- The impossible just takes a little longer Patrick Pirtle wrote:
> Well, progress, of a sort. The following code (along> I'll go try this. However, I would welcome any suggestions > for better ways to do this. with a reference to Microsoft's Scripting runtime) does populate a couple of dictionary objects. However, my test case fails to select the correct case. I suspect I'm close, but am kind of floundering around without *really* understanding the Dictionary object. Private Sub cmdCommand1_Click() Dim ImperialScales As New Dictionary Dim MetricScales As New Dictionary Dim test As String test = "Met Detl 1:10" With ImperialScales .Add "SCALE_0132PLANS", "Plan 1/32""=1'-0""" .Add "SCALE_0116PLANS", "Plan 1/16""=1'-0""" .Add "SCALE_0332PLANS", "Plan 3/32""=1'-0""" End With With MetricScales .Add "SCALE_0105DETLS_METRIC", "Met Detl 1:5" .Add "SCALE_0110DETLS_METRIC", "Met Detl 1:10" .Add "SCALE_0150PLANS_METRIC", "Met Plan 1:50" End With Select Case test Case ImperialScales.Exists(test) Debug.Print "Imperial" Case MetricScales.Exists(test) Debug.Print "Metric" <-----------------This should print Case Else End Select Dim ctr As Variant For Each ctr In MetricScales.Keys Debug.Print ctr & " = " & MetricScales.Item(ctr) <--This works Next End Sub Any ideas? TIA
Show quote
Hide quote
"Patrick Pirtle" <p**@skilling.com> wrote in message Slightly off topic, but I'm surprised that someone hasn't come in to warnnews:OkU7rjQ0FHA.2348@TK2MSFTNGP15.phx.gbl... > Patrick Pirtle wrote: > > > > I'll go try this. However, I would welcome any suggestions > > for better ways to do this. > > > Well, progress, of a sort. The following code (along > with a reference to Microsoft's Scripting runtime) does > populate a couple of dictionary objects. However, > my test case fails to select the correct case. I suspect > I'm close, but am kind of floundering around without > *really* understanding the Dictionary object. > > > Private Sub cmdCommand1_Click() > Dim ImperialScales As New Dictionary > Dim MetricScales As New Dictionary > Dim test As String > > test = "Met Detl 1:10" > > With ImperialScales > .Add "SCALE_0132PLANS", "Plan 1/32""=1'-0""" > .Add "SCALE_0116PLANS", "Plan 1/16""=1'-0""" > .Add "SCALE_0332PLANS", "Plan 3/32""=1'-0""" > End With > > With MetricScales > .Add "SCALE_0105DETLS_METRIC", "Met Detl 1:5" > .Add "SCALE_0110DETLS_METRIC", "Met Detl 1:10" > .Add "SCALE_0150PLANS_METRIC", "Met Plan 1:50" > End With > > Select Case test > Case ImperialScales.Exists(test) > Debug.Print "Imperial" > Case MetricScales.Exists(test) > Debug.Print "Metric" <-----------------This should print > Case Else > End Select > > Dim ctr As Variant > For Each ctr In MetricScales.Keys > Debug.Print ctr & " = " & MetricScales.Item(ctr) <--This works > Next > > End Sub > > > Any ideas? TIA > you about using the Scripting Runtime. If you are creating a distributed application, the scripting runtime suffers from multiple versions and the fact many Admins 'shut it off'. (If you own the box. Disregard.) Which is a shame as the Dictionary is rather handy and surprisingly faster than the inherent VB Collection. There are a few free "Collection" replacements out there. Also, (fully aware I know next to nothing about your problem domain), all those items look like unique attributes for some kind of object. You may be able to move the 'comparison' switch into a simple query of the object you are chewing on at the moment... Public Function IsPlan( vPlan As String) As Boolean -ralph Ralph wrote:
> Slightly off topic, but I'm surprised that someone hasn't come in to <snip>> warn you about using the Scripting Runtime. MANY thanks to everyone who has responded. I've gotten a number of good ideas from you all. It sounds like a simple function or two would be the easiest for *me* to understand how to do. However, I like the idea of a class with its own "isMemberOf" property (just because I think I'd learn some- thing by doing it that way). Also, thanks for the Scripting Runtime warning. This app *is* used exclusively in-house, but that's good to know. And now, back to floundering around in the code window... Hehe "Patrick Pirtle" <p**@skilling.com> wrote in message Well... you can create a class that contains all of those properties. news:O47e86O0FHA.2924@TK2MSFTNGP15.phx.gbl... > > Is there an easier-to-maintain, or more readable, or > more elegant way to do this? Can I group the constants like: > > Public something ImperialScales > > Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" > Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" > Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" > End something Probably harder to work with. There's no such thing as an array of constants or a class that exposes nothing but constants (unless we're talking about Enum's and only Long's are supported for Enum members) > and then do something like: There are so many ways to do things, it's not funny. This doesn't answer the > > Select Case curScale > Case isAMemberOf (ImperialScales) > textStyle = curScale + " Callouts" > Case isAMemberOf (MetricScales) > ... > End select > > TIA for any help and suggestions. > -------------------------------------------------------- > The impossible just takes a little longer question well... but may give you other ideas. '========= Option Explicit Public Enum ConstantsMap 'must be Public if property is Public SCALE_0132PLANS SCALE_0116PLANS SCALE_0332PLANS ' SCALE_0132DETLS SCALE_0116DETLS SCALE_0332DETLS ' SCALE_0110PLANS SCALE_0120PLANS SCALE_0130PLANS ' SCALE_0105DETLS_METRIC SCALE_0110DETLS_METRIC ' SCALE_0150PLANS_METRIC SCALE_0175PLANS_METRIC ' LastConst = SCALE_0175PLANS_METRIC FirstMetric = SCALE_0105DETLS_METRIC End Enum Private mkStringConstants As Collection Public Property Get TheStrings _ (ByVal StrIndex As ConstantsMap) As String If mkStringConstants Is Nothing Then Call BuildCollection End If If StrIndex >= FirstMetric Then Debug.Print "It's Metric!" End If TheStrings = mkStringConstants(StrIndex) End Property Private Sub BuildCollection() Set mkStringConstants = New Collection mkStringConstants.Add "Plan 1/32""=1'-0""" mkStringConstants.Add "Plan 1/16""=1'-0""" mkStringConstants.Add "Plan 3/32""=1'-0""" mkStringConstants.Add "Detl 1/32""=1'-0""" mkStringConstants.Add "Detl 1/16""=1'-0""" mkStringConstants.Add "Detl 3/32""=1'-0""" mkStringConstants.Add "Plan 1""=10'" mkStringConstants.Add "Plan 1""=20'" mkStringConstants.Add "Plan 1""=30'" mkStringConstants.Add "Met Detl 1:5" mkStringConstants.Add "Met Detl 1:10" mkStringConstants.Add "Met Plan 1:50" mkStringConstants.Add "Met Plan 1:75" End Sub Private Sub Form_Load() Dim eIndex As ConstantsMap 'come up with a random number Randomize eIndex = Rnd * LastConst + 1 Debug.Print TheStrings(eIndex) End Sub '========= -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Please keep all discussions in the groups.. "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote I would have though using two classes (Imperial and Metric) would have> > Is there an easier-to-maintain, or more readable, or > > more elegant way to do this? Can I group the constants like: > > Well... you can create a class that contains all of those properties. > Probably harder to work with. There's no such thing as an array of constants > or a class that exposes nothing but constants (unless we're talking about > Enum's and only Long's are supported for Enum members) made the task easier, not harder. A class would allow the creation of an IsMemberOf function, just as he was looking for.... LFS
Show quote
Hide quote
"Patrick Pirtle" <p**@skilling.com> wrote in message SCALE_0108PLANS, SCALE_0104PLANS, _news:O47e86O0FHA.2924@TK2MSFTNGP15.phx.gbl... > I have a number of constants such as (abbreviated list): > > Public Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" > Public Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" > Public Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" > > Public Const SCALE_0132DETLS = "Detl 1/32""=1'-0""" > Public Const SCALE_0116DETLS = "Detl 1/16""=1'-0""" > Public Const SCALE_0332DETLS = "Detl 3/32""=1'-0""" > > Public Const SCALE_0110PLANS = "Plan 1""=10'" > Public Const SCALE_0120PLANS = "Plan 1""=20'" > Public Const SCALE_0130PLANS = "Plan 1""=30'" > > Public Const SCALE_0105DETLS_METRIC = "Met Detl 1:5" > Public Const SCALE_0110DETLS_METRIC = "Met Detl 1:10" > > Public Const SCALE_0150PLANS_METRIC = "Met Plan 1:50" > Public Const SCALE_0175PLANS_METRIC = "Met Plan 1:75" > > > In my program, I frequently need to compare a variable to these constants, > such as: > > Select Case curScale > 'Imperial Architectural and Civil Plan Scales > Case SCALE_0132PLANS, SCALE_0116PLANS, SCALE_0332PLANS, > SCALE_0308PLANS, SCALE_0110PLANS, SCALE_0120PLANS, SCALE_0130PLANS, SCALE_0140PLANS, _> SCALE_0150PLANS, SCALE_0160PLANS, SCALE_0180PLANS, SCALE_0104DETLS, SCALE_0308DETLS, _SCALE_01100PLANS, SCALE_01200PLANS > textStyle = curScale + " Callouts" > 'Imperial Architectural Detail Scales > Case SCALE_0132DETLS, SCALE_0116DETLS, SCALE_0108DETLS, Show quoteHide quote > SCALE_0102DETLS, SCALE_0304DETLS, SCALE_0100DETLS, Patrick,SCALE_0112DETLS, SCALE_0300DETLS > textStyle = "Detl Callouts" > 'Metric Plan Scales > Case SCALE_01200PLANS_METRIC, SCALE_01100PLANS_METRIC, _ > SCALE_0175PLANS_METRIC, SCALE_0150PLANS_METRIC, SCALE_0125DETLS_METRIC > textStyle = curScale + " Callouts" > 'Metric Detail Scales > Case SCALE_0125DETLS_METRIC, SCALE_0120DETLS_METRIC, SCALE_0116DETLS_METRIC, _ > SCALE_0110DETLS_METRIC, SCALE_0105DETLS_METRIC > textStyle = "Detl Callouts" > Case Else > End Select > > Is there an easier-to-maintain, or more readable, or > more elegant way to do this? Can I group the constants like: > > Public something ImperialScales > > Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" > Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" > Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" > End something > > and then do something like: > > Select Case curScale > Case isAMemberOf (ImperialScales) > textStyle = curScale + " Callouts" > Case isAMemberOf (MetricScales) > ... > End select > > TIA for any help and suggestions. > -------------------------------------------------------- > The impossible just takes a little longer > I see your dilemma, this does appear to be an inefficient use of Constants. At first glance, it looks like you are really trying to treat these constants more like an Enumeration. An enumeration could help solve a number of your current requirements. For example, you could group them like your example: Public Enum ImperialScales SCALE_0132PLANS = 0 SCALE_0116PLANS = 1 SCALE_0332PLANS = 2 End Enum Or, possibly you could just keep a whole long list in one enumerator, and differentiate them by assigning numeric ranges. For example: Public Enum enmScales 'Reserve values 0 - 9 for Imperial Plan Scales SCALE_0132PLANS = 0 ... 'Reserve values 10 - 19 for Metric Plan Scales SCALE_0150PLANS_METRIC = 10 ... 'Reserve values 20 - 29 for Imperial Detail Scales .... 'Reserve values 30 - 39 for Metric Detail Scales ... End Enum Then in your testing of values, you could test for a range of values, which could determine behaviour. So if the enmScales value is between 20 - 29, then it is an Imperial Detail Scale. Hopefully you get the idea. However, before you jump into that... You have probably already noticed that the Enumeration type uses numbers (Long to be precise) while you are currently using Strings. So clearly there is a potential for more confusion. So you would probably now need a method to translate the Enumeration value to a String equivalent. Something like: Public Function GetScaleDescription(ByVal Value as enmScales) As String Dim retVal as String Select Case Value Case SCALE_0132PLANS retVal = "Plan 1/32""=1'-0""" Case... End Select GetScaleDescription = retVal End Function So now you could end up with something that might look like: Select Case curScale 'Imperial Architectural and Civil Plan Scales Case is < 10 textStyle = GetScaleDescription(curScale) & " Callouts" 'Metric Plan Scales Case is < 20 textStyle = GetScaleDescription(curScale) & " Callouts" 'Imperial Architectural Detail Scales Case is < 30 textStyle = "Detl Callouts" 'Metric Detail Scales Case is < 40 textStyle = "Detl Callouts" Case Else End Select (Yes, I know that can be trimmed to 2 or less tests, but did this for clear comparison) Of course by now you are already probably seeing some other things as well. What I see after a cursory look at your code, is that it appears that you want your Constant to be used for more than a simple Constant. The variable has other important implications. At minimum, it seems that each value represents the following: Scale Type - Imperial or Metric Scale Usage - Plan or Detail Textual Description I don't know what action you actually take based on your decision tree, but I can take an educated guess. For one, you might want to perform some specific calculation based on the scale ratios. If so, are these values also hard coded somewhere? If it was me, I would probably consider adding a couple more potential properties. Like: Scale Multiplier - Maybe something like 1/16 = 0.0625 or possibly store more discrete values like: Scale Numerator = 1 Scale Denominator = 16 Maybe even what unit you are actually using, Meters, Millimeters, Feet, Inches, etc. Ok, now we have quite a number of related and useful values that can be attributed to one entry. Much more complicated, and also more useful, than a simple Constant. So at this point, I would look into possibly a User Defined Type, but more likely creating a Class out of this. Additionally, I would also probably create a strongly typed collection to house these class items. This could also allow you to easily load the values themselves from some sort of separate resource, such as a Text file, XML File, Database, etc. Then, if you want to add, remove, or change a value, just edit the resource and reload the values, instead of having to actually edit and recompile the code. Additionally, while it may not be a concern, you could Localize the textual description strings and make your code more Local/Language neutral. Since I also like Enumerators as a useful aid to the programmer, I would probably add Enums for ScaleType and ScaleUsage. Public Enum enmScaleType ScaleType_Imperial ScaleType_Metric End Enum Public Enum enmScaleUsage ScaleUsage_Plan ScaleUsage_Detail End Enum Now, your decision tree might look something like: Select Case ScaleItem.ScaleUsage 'Assume this returns an enmScaleUsage value Case enmScaleUsage.ScaleUsage_Plan textStyle = ScaleItem.Description & " Callouts" Case enmScaleUsage.ScaleUsage_Detail textStyle = "Detl Callouts" End Select Yeah, I know that at this point you basically have the exact same amount of code as the earlier suggestion, but consider all the other possibilities. I know that might be a lot to digest, and may or may not really fit into what you have going on. But from the little bit I've seen, "I" would probably pursue the Class idea. While creating the Class and associated Strongly Typed Collection might at first seem to be a lot more work than Constants, I believe in the long run it could very well turn out to be much less code. At the very least, in my opinion just might end up being easier to maintain. Gerald
Show quote
Hide quote
"Patrick Pirtle" <p**@skilling.com> wrote in message SCALE_0108PLANS, SCALE_0104PLANS, _news:O47e86O0FHA.2924@TK2MSFTNGP15.phx.gbl... > I have a number of constants such as (abbreviated list): > > Public Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" > Public Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" > Public Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" > > Public Const SCALE_0132DETLS = "Detl 1/32""=1'-0""" > Public Const SCALE_0116DETLS = "Detl 1/16""=1'-0""" > Public Const SCALE_0332DETLS = "Detl 3/32""=1'-0""" > > Public Const SCALE_0110PLANS = "Plan 1""=10'" > Public Const SCALE_0120PLANS = "Plan 1""=20'" > Public Const SCALE_0130PLANS = "Plan 1""=30'" > > Public Const SCALE_0105DETLS_METRIC = "Met Detl 1:5" > Public Const SCALE_0110DETLS_METRIC = "Met Detl 1:10" > > Public Const SCALE_0150PLANS_METRIC = "Met Plan 1:50" > Public Const SCALE_0175PLANS_METRIC = "Met Plan 1:75" > > > In my program, I frequently need to compare a variable to these constants, > such as: > > Select Case curScale > 'Imperial Architectural and Civil Plan Scales > Case SCALE_0132PLANS, SCALE_0116PLANS, SCALE_0332PLANS, > SCALE_0308PLANS, SCALE_0110PLANS, SCALE_0120PLANS, SCALE_0130PLANS, SCALE_0140PLANS, _> SCALE_0150PLANS, SCALE_0160PLANS, SCALE_0180PLANS, SCALE_0104DETLS, SCALE_0308DETLS, _SCALE_01100PLANS, SCALE_01200PLANS > textStyle = curScale + " Callouts" > 'Imperial Architectural Detail Scales > Case SCALE_0132DETLS, SCALE_0116DETLS, SCALE_0108DETLS, Show quoteHide quote > SCALE_0102DETLS, SCALE_0304DETLS, SCALE_0100DETLS, Based on the constants that you've provided the following functions may beSCALE_0112DETLS, SCALE_0300DETLS > textStyle = "Detl Callouts" > 'Metric Plan Scales > Case SCALE_01200PLANS_METRIC, SCALE_01100PLANS_METRIC, _ > SCALE_0175PLANS_METRIC, SCALE_0150PLANS_METRIC, SCALE_0125DETLS_METRIC > textStyle = curScale + " Callouts" > 'Metric Detail Scales > Case SCALE_0125DETLS_METRIC, SCALE_0120DETLS_METRIC, SCALE_0116DETLS_METRIC, _ > SCALE_0110DETLS_METRIC, SCALE_0105DETLS_METRIC > textStyle = "Detl Callouts" > Case Else > End Select > > Is there an easier-to-maintain, or more readable, or > more elegant way to do this? Can I group the constants like: > > Public something ImperialScales > > Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" > Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" > Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" > End something > > and then do something like: > > Select Case curScale > Case isAMemberOf (ImperialScales) > textStyle = curScale + " Callouts" > Case isAMemberOf (MetricScales) > ... > End select > > TIA for any help and suggestions. > -------------------------------------------------------- > The impossible just takes a little longer > > of some help: Function GetCallouts(ByVal sScale As String) As String If InStr(sScale, "Detl") > 0 Then GetCallouts = sScale & " Detl Callouts" Else GetCallouts = sScale & " Callouts" End If End Function Function IsImperialScale(ByVal sScale As String) As Boolean IsImperialScale = (Left$(sScale, 3) <> "Met") End Function You'll need to be very consistent with your declarations though. HTH, Jim Edgar > Function GetCallouts(ByVal sScale As String) As String Oops, I looked a little closer at your code and the following seems to be> If InStr(sScale, "Detl") > 0 Then > GetCallouts = sScale & " Detl Callouts" > Else > GetCallouts = sScale & " Callouts" > End If > End Function > what you're looking for. Function GetCallouts(ByVal sScale As String) As String If InStr(sScale, "Detl") > 0 Then GetCallouts = "Detl Callouts" Else GetCallouts = sScale & " Callouts" End If End Function
Show quote
Hide quote
"Patrick Pirtle" <p**@skilling.com> wrote in message Here is my thought:news:O47e86O0FHA.2924@TK2MSFTNGP15.phx.gbl... >I have a number of constants such as (abbreviated list): > > Public Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" > Public Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" > Public Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" > > Public Const SCALE_0132DETLS = "Detl 1/32""=1'-0""" > Public Const SCALE_0116DETLS = "Detl 1/16""=1'-0""" > Public Const SCALE_0332DETLS = "Detl 3/32""=1'-0""" > > Public Const SCALE_0110PLANS = "Plan 1""=10'" > Public Const SCALE_0120PLANS = "Plan 1""=20'" > Public Const SCALE_0130PLANS = "Plan 1""=30'" > > Public Const SCALE_0105DETLS_METRIC = "Met Detl 1:5" > Public Const SCALE_0110DETLS_METRIC = "Met Detl 1:10" > > Public Const SCALE_0150PLANS_METRIC = "Met Plan 1:50" > Public Const SCALE_0175PLANS_METRIC = "Met Plan 1:75" > > > > Is there an easier-to-maintain, or more readable, or > more elegant way to do this? Can I group the constants like: > > Public something ImperialScales > > Const SCALE_0132PLANS = "Plan 1/32""=1'-0""" > Const SCALE_0116PLANS = "Plan 1/16""=1'-0""" > Const SCALE_0332PLANS = "Plan 3/32""=1'-0""" > End something > > and then do something like: > > Select Case curScale > Case isAMemberOf (ImperialScales) > textStyle = curScale + " Callouts" > Case isAMemberOf (MetricScales) > ... > End select Not with the constants being strings. If each constant could be represented by a bit value, then you could simply things greatly. Of course, there would be "translation" involved in that too.With some planning and the right use of bit values, you could easily simplify a Select Case as you're wanting. -- Mike Microsoft MVP Visual Basic
insert char in txtbox on key up?
?creating activex control? Ping Ken Halter Newbie: ADO - Access Connection string VBA and ADODB.Recordset question Font Dialog Box kill a proccess for a specific user VB6: What's the command that creates an ARRAY out of a STRING??? GDI API question X 2 Software protection against cracks and piracy |
|||||||||||||||||||||||