|
-
Jan 27th, 2007, 08:03 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] List of Time Zones in right order
Hello, I am trying to list in a combo-box (like in the Time Zone tab of the "Date and Time Properties" of windows).
I am able to this using this code:
http://vbnet.mvps.org/index.html?cod...onedisplay.htm
However the results are not in order. Anybody know how to sort them?
-
Jan 27th, 2007, 09:09 AM
#2
Re: List of Time Zones in right order
If you sort it by Display Name or Std Basis, it will be.
-tg
-
Jan 28th, 2007, 05:17 AM
#3
Re: List of Time Zones in right order
what order do you want them in? i have code to sort them by gmt offset
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 28th, 2007, 10:45 AM
#4
Thread Starter
Hyperactive Member
Re: List of Time Zones in right order
Hello Westconn,
I want it in the same order as in Windows Which is by GMT as in -12,-11...0...11, 12
Thanks for your assistance.
-
Jan 28th, 2007, 03:58 PM
#5
Re: List of Time Zones in right order
this is the code that was given to me to sort the array of timezones and i am using
VB Code:
Private Sub SortArray(ByRef sArray() As String)
Dim i As Long
Dim ArrTemp() As Long
ReDim ArrTemp(UBound(sArray))
For i = LBound(sArray) To UBound(sArray)
ArrTemp(i) = Val(Trim$(Mid(sArray(i), 5, 6)))
Next
BubbleSortNumbers ArrTemp, sArray
End Sub
Private Sub BubbleSortNumbers(varray() As Long, vRealarray() As String)
Dim cnt1 As Long
Dim cnt2 As Long
Dim tmp As Long
Dim tmpStr As String
For cnt1 = UBound(varray) To LBound(varray) Step -1
For cnt2 = LBound(varray) + 1 To cnt1
If varray(cnt2 - 1) > varray(cnt2) Then
'Switch Positions array
tmp = varray(cnt2 - 1)
varray(cnt2 - 1) = varray(cnt2)
varray(cnt2) = tmp
'Switch real array
tmpStr = vRealarray(cnt2 - 1)
vRealarray(cnt2 - 1) = vRealarray(cnt2)
vRealarray(cnt2) = tmpStr
End If
Next cnt2
Next cnt1
End Sub
' call like this
opentimezonelist ' sub to return array of timezones
Dim arrsort() As String
ReDim arrsort(UBound(arrdisplay)) ' array of returned timezones
arrsort = arrdisplay
SortArray arrsort
For i = 0 To UBound(arrsort)
List1.AddItem arrsort(i)
Next
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 28th, 2007, 08:40 PM
#6
Thread Starter
Hyperactive Member
Re: List of Time Zones in right order
Thanks westconn1 works perfectly.
-
Jan 28th, 2007, 11:45 PM
#7
Thread Starter
Hyperactive Member
Re: [RESOLVED] List of Time Zones in right order
Hello westconn1, I added a small piece of code to your code so after the items are sorted using GMT, I do a secondary alphabetical sort. All I did was add an extra condition in the BubbleSortNumbers function where the GMT are identical. Here is the code:
VB Code:
Private Sub SortArray(ByRef strArray() As String)
Dim iCounter As Integer
Dim lngArrayTmp() As Long
On Error Resume Next
ReDim lngArrayTmp(UBound(strArray))
For iCounter = LBound(strArray) To UBound(strArray)
lngArrayTmp(iCounter) = Val(Trim$(Mid$(strArray(iCounter), 5, 6)))
Next
Call BubbleSortNumbers(lngArrayTmp, strArray)
End Sub
Private Sub BubbleSortNumbers(lngArray() As Long, strArray() As String)
Dim iCounter As Integer
Dim jCounter As Integer
Dim lngTmp As Long
Dim strTmp As String
On Error Resume Next
For iCounter = UBound(lngArray) To LBound(lngArray) Step -1
For jCounter = (LBound(lngArray) + 1) To iCounter
If lngArray(jCounter - 1) > lngArray(jCounter) Then
'Switch Positions array
lngTmp = lngArray(jCounter - 1)
lngArray(jCounter - 1) = lngArray(jCounter)
lngArray(jCounter) = lngTmp
'Switch real array
strTmp = strArray(jCounter - 1)
strArray(jCounter - 1) = strArray(jCounter)
strArray(jCounter) = strTmp
ElseIf lngArray(jCounter - 1) = lngArray(jCounter) Then
If StrComp(strArray(jCounter - 1), strArray(jCounter), vbTextCompare) = 1 Then
'Switch Positions array
lngTmp = lngArray(jCounter - 1)
lngArray(jCounter - 1) = lngArray(jCounter)
lngArray(jCounter) = lngTmp
'Switch real array
strTmp = strArray(jCounter - 1)
strArray(jCounter - 1) = strArray(jCounter)
strArray(jCounter) = strTmp
End If
End If
Next jCounter
Next iCounter
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|