|
-
Feb 27th, 2006, 07:23 PM
#1
Thread Starter
Member
[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
-
Feb 27th, 2006, 07:35 PM
#2
Lively Member
Re: Count
so to clarify, you want the if statement to do something if COUNT is odd?
-
Feb 27th, 2006, 07:42 PM
#3
Re: Count
To detect an odd number you would use the Mod operator:
VB Code:
If count Mod 2 = 1 Then
'count is odd.
-
Feb 27th, 2006, 07:44 PM
#4
Thread Starter
Member
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
-
Feb 27th, 2006, 07:46 PM
#5
Sleep mode
private bool IsOdd(int number)
{
if (number % 2 != 0)
return true;
else return false;
}
true = odd #
false = even #
-
Feb 27th, 2006, 07:49 PM
#6
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:
Select Case count
Case 1 To 4, 6, 8, 12 'Matches 1, 2, 3, 4, 6, 8 and 12.
'Do something here.
End Select
-
Feb 27th, 2006, 08:07 PM
#7
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|