TDBTZoneX Object > Features of the TDBTZoneX > Defining DSTStyles |
Each TDBTZoneX object maintains a collection of DST styles that can be applied to its own elements. The DSTStyles property allows you to access this collection at run time. For example, the following loop prints the key names of all user-defined styles to the Visual Basic debug window:
Example Title |
Copy Code
|
---|---|
Dim objTZ As New TDBTZoneX6Lib.TDBTZoneX Dim DSTS As TDBTZoneX6Lib.DSTStyle For Each DSTS In obj.DSTStyles Debug.Print DSTS.Key Next DSTS |
Using the For Each...Next statement is the preferred way to iterate over a collection. However, you can also reference an individual element of the DSTStyles collection by using its one-based index. The following example is equivalent to the previous one, although it is less economical:
Example Title |
Copy Code
|
---|---|
For n = 1 To objTZ.DSTStyles.Count Debug.Print objTZ.DSTStyles(n).Key Next n |
Typically, you will refer to a style by key name. The following example changes the starting month and ending month attribute of an user-defined style named US:
Example Title |
Copy Code
|
---|---|
Dim DSTS As TDBTZoneX6Lib.DSTStyle Set DSTS = objTZ.DSTStyles.Add(, "US", "US & Canada") With DSTS .StartDay = 0 .StartMonth = dbiApril .StartTime = 120 .StartWeekday = dbiSunday .StartWhichWeek = dbi1stWeek .EndDay = 0 .EndMonth = dbiOctober .EndTime = 120 .EndWeekday = dbiSunday .EndWhichWeek = dbiLastWeek .TimeOffset = 60 End With DSTS.StartMonth = dbiMarch DSTS.EndMonth = dbiSeptember |
Note the use of the Dim and Set statements in assigning the US style object to the variable DSTS. The last two lines of this example could have been written as follows:
Example Title |
Copy Code
|
---|---|
objTZ.DSTStyles("US").StartMonth = dbiMarch objTZ.DSTStyles("US").EndMonth = dbiSeptember |
However, this style of coding is less efficient since the US style must be retrieved twice.
You can also use the With...End Withstatement to set multiple properties of a DSTStyle object without explicitly assigning it to a variable:
Example Title |
Copy Code
|
---|---|
With objTZ.DSTStyles("US")
.StartMonth = dbiMarch
.EndMonth = dbiSeptember
End With
|
To create a new style called CN, use the Add method of the DSTStyles collection, and then use the With...End Withstatement to initialize its properties:
Example Title |
Copy Code
|
---|---|
Dim China As TDBTZoneX6Lib.DSTStyle Set China = objTZ.DSTStyles.Add(, "CN") With China .Parent = "US" .Name = "China Beijing" .StartMonth = dbiMarch .StartWhichWeek = dbiLastWeek End With |
You can also use the AddObj method to add an existing independent DSTStyle object into the DSTStylesCollection. An independent style object is not a member of the DSTStylesCollection, but is a standalone object created in code with a Dim or Set statement using the New keyword. For example:
Example Title |
Copy Code
|
---|---|
Dim China As New TDBTZoneX6Lib.DSTStyle With China .Name = "China Beijing" .StartMonth = dbiMarch .StartWhichWeek = dbiLastWeek End With objTZ.DSTStyles.AddObj(, "CN", China) |