|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Verify a signed integer as even or oddOK, This should be simple but I am stuck. I have set up some code to
determing the day of the year based on 1-365(366 for leap year). In
short I have DIMed a variable as an integer and assigned the Julian day
to the variable. I now need to know if the day of the week is an even
or odd day. The program is written in straight old fashioned basic.
This is for a specific application that will be loaded in to a control
module.
I appreciate any and all help given. Thanks, David -- dburnham ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------ dburnham wrote:
> OK, This should be simple but I am stuck. I have set up some code to The straight-forward way to test even/odd is:> determing the day of the year based on 1-365(366 for leap year). In > short I have DIMed a variable as an integer and assigned the Julian > day to the variable. I now need to know if the day of the week is an > even or odd day. The program is written in straight old fashioned > basic. This is for a specific application that will be loaded in to a > control module. (SomeNumber Mod 2) = 0 'even Use the Weekday() function to get day of the week. "dburnham" <dburnham.1xa***@mail.codecomments.com> wrote in message I'm not sure what you mean by the day of the week being odd or even (they're news:dburnham.1xa0tn@mail.codecomments.com... > > OK, This should be simple but I am stuck. I have set up some code to > determing the day of the year based on 1-365(366 for leap year). In > short I have DIMed a variable as an integer and assigned the Julian day > to the variable. I now need to know if the day of the week is an even > or odd day. The program is written in straight old fashioned basic. > This is for a specific application that will be loaded in to a control > module. > all odd for me <g>). I assume you mean giving each day a number representation (1-7), maybe the return from VB's WeekDay function or any number of other functions or maybe even just your own designation, and then determining if that number is odd or even. As far as determining if a number is odd or even, use the Mod operator. (air code) A = 2 If A Mod 2 = 0 Then Debug.Print "number is even" Else Debug.Print "number is odd" End If The Mod operator returns the remainder of a division operation. It's short for "modulus". If you divide any *integer* number by 2, the remainder is always going to be 0 for even numbers and 1 for odd numbers. This doesn't work for real (floating point) numbers. Consider: In VB's Immediate window, type "? 3.6 mod 2" and press Enter. It prints 0 indicating even. Now type in "? 4.6 mod 2" and press Enter. It prints 1 indicating odd. I don't think you can fault VB for this. As far as I know (or actually, as I can remember from high school), an even number, by definition, must be an integer. I just seem to remember that from HS for some reason. Maybe I'm wrong. Also, I think you're going to have problems with a variable declared as an Integer being assigned the Julian day. Might want to change that to a Long or a Date data type. -- Mike Microsoft MVP Visual Basic > I have set up some code to determing the day of the year VB has a function that will give you this, it is called DatePart> based on 1-365(366 for leap year). and it has several options available through its first argument (so you should check it out in the Help files). The argument you want for the day of the year is "y"; here is an example... Dim SomeDate As Date SomeDate = Now Debug.Print DatePart("y", SomeDate) > I now need to know if the day of the week is an even or Why? What will knowing this do for you?> odd day. Rick On Fri, 21 Oct 2005 11:33:48 -0500, dburnham
<dburnham.1xa***@mail.codecomments.com> wrote: > If ( N And 1 ) Then MsgBox "An Odd Number">OK, This should be simple but I am stuck. I have set up some code to >determing the day of the year based on 1-365(366 for leap year). In >short I have DIMed a variable as an integer and assigned the Julian day >to the variable. I now need to know if the day of the week is an even >or odd day. The program is written in straight old fashioned basic. >This is for a specific application that will be loaded in to a control >module.
The Elements of Style revisited.
Intergating Multiple VB6.0 Projects into one: Project Grouping Parsing UNIX text files Is this possible ? How to access related documents in VB through source code? Lost_Focus event of controls doesn't fire Please Explain! Global (Public) variables MSDN Library on network location Object Model Extraction |
|||||||||||||||||||||||