How to determin odd and even numbers

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I need to loop through an array and determine which indexes are odd and
which are even. how can I determine if a number is an odd number or an even
number?
 
moondaddy said:
how can I determine if a number is an odd number or an even
number?

\\\
If i Mod 2 = 0 Then
MsgBox("Even.")
Else
MsgBox("Odd.")
End If
///
 
Mr MVP,

Why do you always use 'MsgBox' when the new way in VB.NET is
'MessageBox.Show(...)'? Otherwise, I agree with your solution
 
moondaddy said:
I need to loop through an array and determine which indexes are odd and
which are even. how can I determine if a number is an odd number or an even
number?


If idx And 1 Then ... 'is always odd


LFS
 
Crouchie,

Although I use forever Messagebox, is your statement not true,

MsgBox versus MessageBox.Show
In Visual Basic .NET, the MsgBox method is a Visual Basic Runtime wrapper
around a call to the MessageBox.Show method from the System.Windows.Forms
namespace. MsgBox does some extra work to emulate the behavior of the Visual
Basic 6 MsgBox function before culminating in a call to MessageBox.Show. The
minute cost of these emulating steps is insignificant, particularly when
compared to the time it takes a user to react to a dialog box.

Note MsgBox returns the same integer values returned by MessageBox.Show.
Strictly speaking MessageBox.Show returns a DialogResult value and MsgBox
returns a MsgBoxResult value. The values in these enumerations have the same
meanings: OK = 1, Yes = 6, No = 7, and so on. You can also use CType to
convert a MsgBoxResult to a DialogResult.

The choice between MsgBox and MessageBox is a matter of consistency. If you
are migrating a Visual Basic 6 application to Visual Basic .NET, there is no
compelling reason to replace calls to MsgBox with MessageBox.Show.

Recommendation: Use MsgBox throughout your code.

From this page

http://msdn.microsoft.com/library/d...tml/vbtchmicrosoftvisualbasicnetinternals.asp

However I have as well the idea that there are more and more a lot of
*recommendations* on MSDN which conflict with each other.

Cor
 
Crouchie1998 said:
Why do you always use 'MsgBox' when the new way in VB.NET is
'MessageBox.Show(...)'? Otherwise, I agree with your solution

* 'MsgBox' is fewer to type that 'MessageBox.Show'.

* 'MsgBox' is part of VB.NET which is not deprecated.

* There are AFAIK no plans to ever remove/deprecate
'MsgBox'.

* 'MsgBox' does not suffer from the loads-of-overloads
productivity stopper.
 
"Herfried K. Wagner [MVP]" wrote
* 'MsgBox' does not suffer from the loads-of-overloads
productivity stopper.

I have to agree, over-loaded overloads can sometimes seem to be
more trouble than they are a help....

<g>
LFS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top