Results 1 to 3 of 3

Thread: A Much Faster Way To Do This?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Question

    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 ??
    Omar
    [email protected]
    http://omar.caribwalk.com
    To God Be The Glory

    I see Tech People ...

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    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

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width