jspencer Posted October 21, 2004 Posted October 21, 2004 Can anyone think of a smart way to use the framework classes to test a number and tell me whether it's even or odd? I can test the last character in the number and if it's 0,2,4,6,8 then the number is even. This doesn't sound very smart though. Thanks. Quote
jspencer Posted October 21, 2004 Author Posted October 21, 2004 This code works, but is decidedly average: Public Function EvenNumber(ByVal Number As Integer) As Boolean Dim Result As Integer Result = Convert.ToInt32(Number.ToString.Substring(Number.ToString.Length - 1, 1)) Select Case Result Case 0, 2, 4, 6, 8 Return True Case Else Return False End Select End Function Quote
Moderators Robby Posted October 21, 2004 Moderators Posted October 21, 2004 try this Dim x As Integer = 48 If x Mod 2 = 0 Then 'true Else 'false End If Quote Visit...Bassic Software
jspencer Posted October 21, 2004 Author Posted October 21, 2004 Thanks Robby, I'll give it a whirl. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.