-
Hi,
I'm trying to load some Time data inside
ComboBox.
Example:
01:00 to 12:59
here is the code that I've used so far.
Code:
Dim Cnt1 as byte
Dim Cnt2 as byte
Combo1.Clear
For Cnt1 = 1 To 12
For Cnt2 = 0 To 59
Combo1.AddItem Format$(Str$(Cnt1), "00") & ":" & _
Format$(Str$(Cnt2), "00")
Next Cnt2
Next Cnt1
This method works, but it works very slow
Any suggestions ??
-
This may be faster
Code:
Dim tm_val As Single, hr As Integer, mi As Integer
Combo1.Clear
For hr = 1 To 12
For mi = 0 To 59
tm_val = hr / 24 + mi / 24 / 60
Combo1.AddItem Format(tm_val, "hh:mm")
Next mi
Next hr
-
I just timed it and Mongo's code is a little faster. You can add a slight bit more speed by temporarily turning off the painting of the screen and by changing Next Cnt1 to Next, etc.
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETREDRAW = &HB
Private Sub Command1_Click()
Dim Cnt1 As Byte
Dim Cnt2 As Byte
Dim tm_val As Single, hr As Integer, mi As Integer
'Temporarily stop the repainting of the combo
SendMessage Combo1.hwnd, WM_SETREDRAW, False, vbEmpty
Combo1.Clear
For Cnt1 = 1 To 12
For Cnt2 = 0 To 59
tm_val = hr / 24 + mi / 24 / 60
Combo1.AddItem Format(tm_val, "hh:mm")
Next
Next
'Repaint and refresh the combo
SendMessage Combo1.hwnd, WM_SETREDRAW, True, vbEmpty
End Sub