Results 1 to 8 of 8

Thread: [RESOLVED] Combo box fill ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Resolved [RESOLVED] Combo box fill ?

    Code:
    For i = 1 To 100
       cboRange.AddItem i 
       Next
     cboRange.ListIndex = 0
    how to fill combo box to look like this

    from 0.00 to 100.00 ?

  2. #2
    Addicted Member Darren M.'s Avatar
    Join Date
    Nov 2005
    Location
    D/FW
    Posts
    200

    Re: Combo box fill ?

    I'm sure there are otherways to do this but just off the cuff....
    vb Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim lngCounter As Long
    4.    
    5.     Combo1.Text = Format(CStr(lngCounter), "##0.00")
    6.     For lngCounter = 0 To 100
    7.         Combo1.AddItem Format(CStr(lngCounter), "##0.00")
    8.     Next lngCounter
    9.    
    10.    
    11. End Sub
    Last edited by Darren M.; Jan 9th, 2012 at 12:23 PM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Combo box fill ?

    Quote Originally Posted by Darren M. View Post
    I'm sure there are otherways to do this but just off the cuff....
    vb Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim lngCounter As Long
    4.    
    5.     Combo1.Text = Format(CStr(lngCounter), "##0.00")
    6.     For lngCounter = 0 To 100
    7.         Combo1.AddItem Format(CStr(lngCounter), "##0.00")
    8.     Next lngCounter
    9.    
    10.    
    11. End Sub
    thx, but what about regional settings, for some region it will be "." and for some ","
    how to avoid that so that will be only "." dot ?

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Combo box fill ?

    simply: Combo1.AddItem CStr(lngCounter) & ".00"
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Combo box fill ?

    can you use currency as your type

    it would i think default to the regional settings

    i dont have access to a vb machine only vba at the moment

    here to help

    just checked vb6 has type currency so thats you sorted or is it?

    if so please close the thread usingthe tool on the top bar and please

    rate the posts that have helped you
    Last edited by incidentals; Jan 9th, 2012 at 01:34 PM.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Combo box fill ?

    Quote Originally Posted by LaVolpe View Post
    simply: Combo1.AddItem CStr(lngCounter) & ".00"
    Thx to both of you...

  7. #7
    Addicted Member Darren M.'s Avatar
    Join Date
    Nov 2005
    Location
    D/FW
    Posts
    200

    Re: Combo box fill ?

    Quote Originally Posted by VB Client/Server View Post
    thx, but what about regional settings, for some region it will be "." and for some ","
    how to avoid that so that will be only "." dot ?
    Ya know, that's a really good question. Unfortunately, I have little to no experience with the "," requirement. (I'm spoiled I suppose.) Let me play around w/ that a bit and I'll see if I can work up something a bit more dynamic. It's cold and rainy here today, I need a challenge. Thanks!

  8. #8
    Addicted Member Darren M.'s Avatar
    Join Date
    Nov 2005
    Location
    D/FW
    Posts
    200

    Re: [RESOLVED] Combo box fill ?

    Well, I wish I could claim this code as my own but I stole it from a Google search...
    http://visualbasic.about.com/b/2005/...k-for-vb-6.htm

    The suggestion there implemented in the code above, with LaVolpe's suggested execution.
    (So simple.....)
    This works in the US. Please test w/ your region and advise.

    [edit]
    Just tested on my Windows 7 w/ different regional settings, works great.
    [/edit]

    vb Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim strLocalDecimal As String
    4.     Dim strLocalComma   As String
    5.     Dim lngCounter      As Long
    6.     Dim strErrMsg       As String
    7.  
    8. On Error GoTo ERRORHANDLER
    9.    
    10.    
    11.     strLocalDecimal = Mid$(CStr(11 / 10), 2, 1)
    12.     strLocalComma = Chr$(90 - Asc(strLocalDecimal))
    13.      
    14.     Combo1.Text = CStr(lngCounter) & strLocalDecimal & "00"
    15.    
    16.     For lngCounter = 0 To 100
    17.         Combo1.AddItem CStr(lngCounter) & strLocalDecimal & "00"
    18.     Next lngCounter
    19.    
    20.    
    21. GoTo OVERERROR
    22.  
    23. ERRORHANDLER:
    24.     If LenB(strErrMsg) = 0 Then
    25.         strErrMsg = Err.Number & ": " & Err.Description
    26.     End If
    27.  
    28.     MsgBox strErrMsg, vbCritical, "Error"
    29. OVERERROR:
    30.    
    31.    
    32. End Sub
    Last edited by Darren M.; Jan 9th, 2012 at 03:04 PM.

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