Results 1 to 11 of 11

Thread: math, simple logic

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2009
    Posts
    492

    math, simple logic

    is my logic problem?

    I want that number "75", foreach 20
    show result:
    0
    20
    40
    60
    75

    any advice please!


    Code:
    Private Sub Command1_Click()
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    
    a = "75"
    
    b = a Mod 20
    c = a \ 20
    
    
    Dim i As Integer
    For i = 0 To a Step 20
    List1.AddItem i
    Next i
    
    List1.AddItem b
    List1.AddItem c
    
    
    End Sub
    Last edited by rpool; Jun 16th, 2011 at 02:57 AM.

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

    Re: math, simple logic

    i m not sure that what u r expecting, but something like this...
    Code:
    Private Sub Command1_Click()
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    
    a = 75
    b = 20
    
    c = a \ b
    
    Dim i As Integer
    For i = 0 To c
    List1.AddItem i * b
    Next i
    
    List1.AddItem a
    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
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: math, simple logic

    after the loop
    vb Code:
    1. if not i = a then list1.additem a
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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

    Re: math, simple logic

    pete, is it to avoid repeat the last value when a mod b = 0? if yes, i think it is like this after the loop
    Code:
    If Not (i - 1) * b = a Then List1.AddItem a
    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
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: math, simple logic

    is it to avoid repeat the last value when a mod b = 0?
    the requested result in th op showed the values for each step and the max value, regardless of whether it was a step
    show result:
    0
    20
    40
    60
    75
    at least that was my interpretation of it
    as far as i could see the mod result was not required
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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

    Re: math, simple logic

    actuly, if a mod b =0 then the max value is achieved in the loop itself, so hav to avoid the same value repeat again in the list
    Code:
    If Not b * c = a Then List1.AddItem a
    'or
    If Not a Mod b = 0 Then List1.AddItem a
    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
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: math, simple logic

    so hav to avoid the same value repeat again in the list
    i did that with not i = a
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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

    Re: math, simple logic

    actuly 'i' = quotient of a/b, so 'i' cant be equal to 'a' unless 'b' = 1
    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
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: math, simple logic

    as i is the counter of the loop, after the loop it is equal to the last step, in this case 60, so not = to a

    if it was step 25 or a = 80 then i would = a
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: math, simple logic

    Quote Originally Posted by westconn1 View Post
    as i is the counter of the loop, after the loop it is equal to the last step, in this case 60, so not = to a

    if it was step 25 or a = 80 then i would = a
    That's not true. After the loop, the value of i will go one more extra step beyond the last step.
    Code:
    For i = 0 to 13 step 3
       '-- do nothing
    Next
    Debug.Print i '-- at this point: i = 15
    Why not do it like this without extra calculation:
    (a - 1) is used to avoid (i = a) within the loop.
    Code:
    Private Sub Command1_Click()
        Dim a As Long
        Dim b As Long
        Dim i As Long
        
        a = 75
        b = 20
        
        For i = 0 To (a - 1) Step b
            List1.AddItem i
        Next
        List1.AddItem a
    End Sub
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

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

    Re: math, simple logic

    yes it's good anhn.
    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