![]() |
|
#3
|
|||
|
|||
|
I'm just noticing that there are a number of items which use strings labels where the 'elegance' of the code might be improved by enumertion based on string rather than Longs
Such items include • Custom Document Properties • Custom XML Parts • CustomUI Ribbon Control Identifiers • Collections/Scripting Dictionaries • User types that need string labels (e.g. user defined styles. For example I have a set of names for elements in a CustomXML part. There are many sets of these elements. Code:
Enum XMLTags TagName1 = "Name1" TagName2 = "Name2" TagName3 = "Name3" .... TagName25 End enum For myTag = TagName1 to TagName13 <Code for each tag> Next defining the TagNames as Constants, Adding the Constant to an Array, defining an enumeration to index the TagNames in the array and then Code:
Enumeration for tag index Array for tag names Assgning values to the name array then For myTagIndex = TagNameArray(enTagName1) to TagNameArray(enTageName13) <code relating to tag> Next Code:
Const TagBase as string="Name" Dim myTag as String Dim myTagIndex as Long For myTagIndex=1 to 13 myTag = TagBase & myTabIndex if Dictionary(Key:=myTag).objectitem=<a value> then end if Next None of the above cause me problems, but they do add an amount of coding 'cruft' that could be avoided with enumerated strings. Now I hold my hands up and admit that I'm self taught with the aid of this forum, VBA in a Nutshell book, the sometimes useful MS help pages and other random reading via Google so it may be that I'm missing something very obvious. In a nutshell I'm not stuck, just wondering about the best way to improve the readability of my code. |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to Dim a substring between two strings
|
dwirony | Word VBA | 4 | 10-28-2016 07:51 AM |
| VBA code to extract strings | twozedz | Excel Programming | 1 | 05-15-2016 06:00 AM |
Search with multiple strings
|
silverspr | Excel | 7 | 03-03-2013 04:45 PM |
Removing Character Strings
|
digitalhecht | Word | 2 | 10-17-2011 12:53 PM |
update style of all strings available between two specific strings
|
vikrantkale | Word | 1 | 03-28-2011 06:13 PM |