Results 1 to 5 of 5

Thread: [RESOLVED] Need help Populate (Height or Tall) in combo box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    328

    Resolved [RESOLVED] Need help Populate (Height or Tall) in combo box

    Name:  Height.jpg
Views: 227
Size:  16.7 KB

    How do I sort this out?

    Example :
    4'8"
    4'9"
    4'10"
    4'11"
    4'12"
    5'1"
    5'2"
    5'3"
    and so on....

    Code:
    Dim iCtr As Integer
    Dim iLoop As Integer
    
    For iCtr = 0 To 12
    
        For iLoop = 4 To 6
            List1.AddItem iLoop & "'" & Format(iCtr, "#0") & """"
        Next iLoop
       
    Next
    Any Help?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    328

    Re: Need help Populate (Height or Tall) in combo box

    in combobox or listbox

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need help Populate (Height or Tall) in combo box

    You need to reverse your loops, make iLoop the outter loop and iCtr the inner loop also iCtr should be 0 to 11 so you don't end up with something like 4'12"

    So when iLoop=4
    iCtr= 0 to 11 and you get
    4' 0"
    4'1"
    ...
    4'11"

    Then iLoop becomes 5 and you get
    5'0"
    ...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    328

    Re: Need help Populate (Height or Tall) in combo box

    Quote Originally Posted by DataMiser View Post
    You need to reverse your loops, make iLoop the outter loop and iCtr the inner loop also iCtr should be 0 to 11 so you don't end up with something like 4'12"

    So when iLoop=4
    iCtr= 0 to 11 and you get
    4' 0"
    4'1"
    ...
    4'11"

    Then iLoop becomes 5 and you get
    5'0"
    ...

    Code:
    Public Sub heightLister(cbo As ComboBox)
    Dim iWeight As Integer
    
    cbo.Clear
    
    Dim iCtr As Integer
    Dim iLoop As Integer
    
    For iLoop = 4 To 6
        
        If iLoop = 4 Then
        
            For iCtr = 0 To 12
                cbo.AddItem iLoop & "'" & Format(iCtr, "#0") & """"
            Next
            
        ElseIf iLoop = 5 Then
        
            For iCtr = 0 To 12
                cbo.AddItem iLoop & "'" & Format(iCtr, "#0") & """"
            Next
        ElseIf iLoop = 6 Then
        
            For iCtr = 0 To 12
                cbo.AddItem iLoop & "'" & Format(iCtr, "#0") & """"
            Next
               
        End If
        
    Next
    
    End Sub
    These code solve my problem.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [RESOLVED] Need help Populate (Height or Tall) in combo box

    You don't need any of those ifs in there. Why did you add those, all you are doing is repeating the code three times.

    All you need is
    Code:
    For iLoop = 4 To 6 
            For iCtr = 0 To 12
                cbo.AddItem iLoop & "'" & Format(iCtr, "#0") & """"
            Next     
    Next

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