Results 1 to 6 of 6

Thread: cutting this code down to size?

  1. #1

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    i have 26 comboboxes ... the first combobox has the #'s 2 to 25 ... what that is supposed to do is make the other 25 comboboxes either be visible or not (they r in an array) lets say u click on 12 in that first combobox ... then the first 12 comboboxes should be visible n the rest not visible ... this part of my long tedious code ... the first combobox is named "cmbnumbers" n the rest are called cmbgrade() ...

    Select Case cmbnumbers.ListIndex
    Case Is = 0
    For cmbsvisible = 0 To 24
    cmbgrade(cmbsvisible).Visible = True
    Next cmbsvisible
    Case Is = 1
    For cmbsvisible = 0 To 23
    cmbgrade(cmbsvisible).Visible = True
    Next cmbsvisible
    cmbgrade(24).Visible = False
    Case Is = 2
    For cmbsvisible = 0 To 22
    cmbgrade(cmbsvisible).Visible = True
    Next cmbsvisible
    cmbgrade(24).Visible = False
    cmbgrade(23).Visible = False
    Case Is = 3
    For cmbsvisible = 0 To 21
    cmbgrade(cmbsvisible).Visible = True
    Next cmbsvisible
    cmbgrade(24).Visible = False
    cmbgrade(23).Visible = False
    cmbgrade(22).Visible = False
    Case Is = 4
    For cmbsvisible = 0 To 20
    cmbgrade(cmbsvisible).Visible = True
    Next cmbsvisible
    cmbgrade(24).Visible = False
    cmbgrade(23).Visible = False
    cmbgrade(22).Visible = False
    cmbgrade(21).Visible = False
    Case Is = 5
    For cmbsvisible = 0 To 19
    cmbgrade(cmbsvisible).Visible = True
    Next cmbsvisible
    cmbgrade(24).Visible = False
    cmbgrade(23).Visible = False
    cmbgrade(22).Visible = False
    cmbgrade(21).Visible = False
    cmbgrade(20).Visible = False

    u can see how it starts to get bigger ... by the way i'm working backwards on this thing so it might be a little confusing (i know it was for me)


  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Try this:
    Code:
    iList = CInt(cmbnumbers.ListIndex)
    For cmbvisible = 0 to iList
    cmbgrade(cmbvisible).Visible = True
    Next
    For cmbvisible = (iList + 1) to 25
    cmbgrade(cmbvisible).Visible = False
    Next
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    Hi theman32x

    What you are doing in your code appears to be different to what you are explaining. This function will do what you want, I think.

    Code:
    Private Sub cmbNumbers_Click()
    For cmbsVisible = 0 To 24
      If cmbsVisible > cmbNumbers.ListIndex Then
        cmbGrade(cmbsVisible).Visible = False
      Else
        cmbGrade(cmbsVisible).Visible = True
      End If
    Next cmbsVisible
    End Sub
    This will mean if you click on 5 in the cmbNumbers, the first 5 cmbGrades will be visible. If this is the wrong way round (which it appears to be from your code), switch the true and false statements around.

    Hope this helps
    Andrew Empson
    vb6(ent) SP4

  4. #4

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    a little different from what i want

    ur code sure cuts down on all that coding i did ... however, it starts hidden or making the comboboxes visible from the bottom up ... i switched the true n false n it does it right but leaves the first combobox of the 25 invisible ... i'm fooling around with it but i'm not getting anywhere ...

  5. #5
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    It does that because you only have 23 listitems (2-25) with 24 combo boxes. If you want the first one to remain visible, you can do it like this

    Code:
    For cmbsVisible = 0 To 24
      If cmbsVisible >= cmbNumbers.ListIndex Then
        cmbGrade(cmbsVisible).Visible = True
      Else
        cmbGrade(cmbsVisible).Visible = False
      End If
    Next cmbsVisible
    End Sub
    but you'll have 2 visible at the end. If that's not what you want, can you have your cmbNumbers going from 1 to 25 rather than 2? then you can just do this:

    Code:
    For cmbsVisible = 0 To 24
      If cmbsVisible >cmbNumbers.ListIndex Then
        cmbGrade(cmbsVisible).Visible = True
      Else
        cmbGrade(cmbsVisible).Visible = False
      End If
    Next cmbsVisible
    End Sub
    Hope this helps
    Andrew Empson
    vb6(ent) SP4

  6. #6

    Thread Starter
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    nope

    i can't have it going from 1 to 25 instead of 2 cause those 2 comboboxes have #'s from 1 to 100 that i will need to average out ... therefore i at least need the first 2 comboboxes visible ... but thanks anyways ... with ur code n realistic's i manage to get it to work ... thanks for all ur help

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