Results 1 to 7 of 7

Thread: [RESOLVED] Count

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Location
    Kent
    Posts
    40

    Resolved [RESOLVED] Count

    Hi all,
    I'm doing a quiz. Every time the user clicks on the question button a count is increased by 1 (count+=1).
    What i want to do is when count equals say 1,3,5,7,9 etc something will happen. I want to do this in one IF - THEN statment instead of having IF count = 1 THEN do something,IF count = 3 THEN do something?
    It's only easy if you know!
    VB.NET2003/1.1
    VB2005/2.0

  2. #2
    Lively Member Luc L.'s Avatar
    Join Date
    Jan 2005
    Posts
    122

    Re: Count

    so to clarify, you want the if statement to do something if COUNT is odd?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Count

    To detect an odd number you would use the Mod operator:
    VB Code:
    1. If count Mod 2 = 1 Then
    2.     'count is odd.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2005
    Location
    Kent
    Posts
    40

    Re: Count

    No not really, it could be any number.....
    if count hits lets say five different numbers do i have to write five IF, THEN statements or can i write one IF, THEN statement to include the five numbers. (if count = 1 2 3 4 5 then
    do something
    end if
    It's only easy if you know!
    VB.NET2003/1.1
    VB2005/2.0

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    private bool IsOdd(int number)
    {
    if (number % 2 != 0)
    return true;
    else return false;
    }

    true = odd #
    false = even #

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Count

    So you're saying that odd numbers is not the general case? Why give such a specific example if it can be anything? Anyway, if there is a pattern to the number syou want to catch then you'll need to let us know what that pattern is. If there is no patter then you can use a Select Case to catch them all with one line:
    VB Code:
    1. Select Case count
    2.             Case 1 To 4, 6, 8, 12 'Matches 1, 2, 3, 4, 6, 8 and 12.
    3.                 'Do something here.
    4.         End Select
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2005
    Location
    Kent
    Posts
    40

    Re: Count

    I do apologize if my thread was misleading . I did mean random numbers.
    Select case will do just fine.
    thank you for your help.
    It's only easy if you know!
    VB.NET2003/1.1
    VB2005/2.0

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