Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 07-20-2017, 01:23 AM
slaycock slaycock is offline A wish for enumerated strings Windows 7 64bit A wish for enumerated strings Office 2013
Expert
A wish for enumerated strings
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

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
Rather than

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
Or constructing the tag name on the run

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.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
A wish for enumerated strings 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
A wish for enumerated strings Search with multiple strings silverspr Excel 7 03-03-2013 04:45 PM
A wish for enumerated strings Removing Character Strings digitalhecht Word 2 10-17-2011 12:53 PM
A wish for enumerated strings update style of all strings available between two specific strings vikrantkale Word 1 03-28-2011 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft