Results 1 to 10 of 10

Thread: find how many times a cirtain number falls in a Range of numbers

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2009
    Posts
    177

    find how many times a cirtain number falls in a Range of numbers

    Hi,
    Iam trying to create a small pick 4 program where i want to find out how many
    times a numer falls whithing a group of numbers.
    For example if I have numbers 0 to 9 and then divide this numbers in 4 groups
    0 to 2, 3 to 4, 5 to 5 and 7 to 9. and if the number I want to use is 1224, what I would like for the program to show is: 0 to 2 = 3 and 3 to 4 = 1.
    Here I include the code that Iam using.
    Code:
    Private Sub CheckForSeconds()
    note: Iam getting the value from another Flexgrid on form1.
    
    Dim i3 As Integer
    Dim c3(10) As Integer
    Dim d3 As Integer
    
    c3(1) = 0
    c3(2) = 0
    c3(3) = 0
    c3(4) = 0
    With Form1.Grid1
    For i3 = 1 To .Rows - 1
            For d3 = 1 To 4
    If .TextMatrix(i3, d3) <= 2 Then 'values 0-1-2
    c3(1) = 1
     Grid1.TextMatrix(i3, 4) = c3(1) + 1
    
    End If
    
    If .TextMatrix(i3, d3) = 3 Or .TextMatrix(i3, d3) = 4 Then 'values 3-4
    c3(2) = 1
     Grid1.TextMatrix(i3, 5) = c3(2) + 1
    End If
    
    If .TextMatrix(i3, d3) = 5 Or .TextMatrix(i3, d3) = 6 Then 'values 5-6
    c3(3) = 1
     Grid1.TextMatrix(i3, 6) = c3(3) + 1
    End If
    
    If .TextMatrix(i3, d3) > 6 Then  'values 7-8-9
    c3(4) = 1
     Grid1.TextMatrix(i3, 7) = c3(4) + 1
    End If
    
    
    Next
    
    
    
    Next
    
    
    
    End With
    
    
    End Sub

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: find how many times a cirtain number falls in a Range of numbers

    i m not using the grids, this is just an example of getting the counts of each group, just try and feedback.
    Code:
    Private Sub Command1_Click()
    Dim Grp(3) As Boolean, GrpCnt(3) As Integer
    Dim Myval As Long, num As Integer, i As Integer, j As Integer
    
    Myval = 1224
    
    'reset counts
    For j = LBound(Grp) To UBound(Grp)
        GrpCnt(j) = 0
    Next
    
    For i = 1 To Len(Myval)
        num = Val(Mid$(Myval, i, 1))
        
        'add more groups if need
        Grp(0) = num >= 0 And num <= 2
        Grp(1) = num >= 3 And num <= 4
        Grp(2) = num >= 5 And num <= 5
        Grp(3) = num >= 7 And num <= 9
    
        For j = LBound(Grp) To UBound(Grp)
            If Grp(j) = True Then
                GrpCnt(j) = GrpCnt(j) + 1
            End If
        Next
    Next
    
    For j = LBound(Grp) To UBound(Grp)
        Debug.Print "Grp"; j + 1; "="; GrpCnt(j)
    Next
    End Sub
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2009
    Posts
    177

    Re: find how many times a cirtain number falls in a Range of numbers

    Thanks,Seenu 1st,
    Your code works ok but it only prints to a form.
    Iam trying to use it with my flexgrid. since
    I use the flexgrid to compare to older values.
    Monti124

  4. #4
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: find how many times a cirtain number falls in a Range of numbers

    yes it's just an exampleto get the groups, try the logic with gids, if u stuck anywhere, me or someone will help u.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2009
    Posts
    177

    Re: find how many times a cirtain number falls in a Range of numbers

    seenu,
    I try to use the group cont in my fgrid but
    it apparently the last part of the code
    "Grp"; j + 1; "="; GrpCnt(j)
    ony works with the print statement.

    Monti124

  6. #6
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: find how many times a cirtain number falls in a Range of numbers

    where do u need to use that part of code?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2009
    Posts
    177

    Re: find how many times a cirtain number falls in a Range of numbers

    this is the way I tried with your code

    Code:
    Private Sub CheckForSeconds()
    Dim Grp(3) As Boolean, GrpCnt(3) As Integer
    Dim Myval As Long, num As Integer, i As Integer, j As Integer
    Dim R As Integer
    
    
    
    With Grid1
    
    For R = 1 To .Rows - 1
           
    Myval = .TextMatrix(R, 1) ' This is what I added.
    
    'reset counts
    For j = LBound(Grp) To UBound(Grp)
        GrpCnt(j) = 0
    Next
    
    For i = 1 To Len(Myval)
        num = Val(Mid$(Myval, i, 1))
        
        'add more groups if need
        Grp(0) = num >= 0 And num <= 2
        Grp(1) = num >= 3 And num <= 4
        Grp(2) = num >= 5 And num <= 5
        Grp(3) = num >= 7 And num <= 9
    
        For j = LBound(Grp) To UBound(Grp)
            If Grp(j) = True Then
                GrpCnt(j) = GrpCnt(j) + 1
            End If
        Next
    Next
    
    For j = LBound(Grp) To UBound(Grp)
        Debug.Print "Grp"; j + 1; "="; GrpCnt(j)
        
        ' this is where I need to add the code
        
        .TextMatrix(R, 4) = Grp(1) count result
        .TextMatrix(R, 5) = Grp(2) count result
        .TextMatrix(R, 6) = Grp(3) count result
        '.TextMatrix(R, 7) = Grp(4) count result
        
        
    Next
    
    
    
    End Sub

  8. #8
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: find how many times a cirtain number falls in a Range of numbers

    no need to use the for next if u dont want to loop, just try like this
    Code:
        .TextMatrix(R, 4) = GrpCnt(0) 'count result
        .TextMatrix(R, 5) = GrpCnt(1)  'count result
        .TextMatrix(R, 6) = GrpCnt(2) 'count result
        .TextMatrix(R, 7) = GrpCnt(3)  'count result
    and dont use R for the Row value, better put the number directly.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2009
    Posts
    177

    Re: find how many times a cirtain number falls in a Range of numbers

    Thank you Seenu the code works as I spected.

  10. #10
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: find how many times a cirtain number falls in a Range of numbers

    happy to help, pls mark thread as resolved using thread tools above.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


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