Results 1 to 3 of 3

Thread: Percentages

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Percentages

    I have an idea although I do not know how to excute it. I have 8 labels as follows:

    Below Basic: 0, Basic: 0, Proficient: 0, Advance: 0
    "0-49" "50-79" "80-95" "96-100"

    Now I have the following data:

    John Smith 50
    Jane Doe 81
    Person 3 30
    Person 4 99

    How can I get the data to check to see what category it falls under and add to the appropriate place?

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

    Re: Percentages

    Extract the last value of the label caption using InStr() & Mid$() or even use Split().
    For John Smith, compare 50 to see if <= that extracted value

    Another option is to store the high value of each label in its TAG property. The compare values to it, i.e., If 50 <= Val(Label1.Tag)
    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}

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Percentages

    Here is one example. To make the data easy to access for the demo I'm loading it into a list box and pumping the results out to a message box.
    Code:
    Private Sub Command1_Click()
    Dim intRanking(3) As Integer
    Dim i As Integer
    Dim x As Integer
    Dim strLine() As String
    Dim strValue As String
    
        
        For i = 0 To List1.ListCount - 1
            strLine = Split(List1.List(i), " ")
            strValue = strLine(UBound(strLine))
            
            Select Case Val(strValue)
                Case Is < 50
                    x = 0
                Case Is < 80
                    x = 1
                Case Is < 96
                    x = 2
                Case Else
                    x = 3
            End Select
            
            intRanking(x) = intRanking(x) + 1
        Next i
        
        MsgBox "Below Basic: " & intRanking(0) & vbCrLf & _
                "Basic: " & intRanking(1) & vbCrLf & _
                "Proficient: " & intRanking(2) & vbCrLf & _
                "Advance: " & intRanking(3)
    
    End Sub
    
    Private Sub Form_Load()
        List1.AddItem "John Smith 50"
        List1.AddItem "Jane Doe 81"
        List1.AddItem "Person 3 30"
        List1.AddItem "Person 4 99"
        List1.AddItem "Person 5 42"
        List1.AddItem "Person 6 87"
    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