VB Script array

freezilla
freezilla used Ask the Experts™
on
I'm nearly done with a project and I've got the right idea, but I'm not sure if I'm implementing it correctly.

The rundown, I've got an Access DB (no way around this) with 28 tables, two for each day of the week covering two weeks.

Now what I want to do is have my code display one week and if it's not that week, display the other.  I've got that set up, but I just want to make sure that my formatting is correct.

Here's what I have:
<%
ctime = FormatDateTime(Time,vbShortTime)
cday = WeekDayName(WeekDay(Date))
cweek = DatePart("ww", Now)
%>

As of this writing we're in week 21.

So I want to say...
<% if cweek = "21" or "23" or "25" then%> (the ... would represent the other odd weeks in the year.

Display the code for the odd weeks.

<% else %>
Display the even number week's code.
<% end if %>

Would that work?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Instead of:
<% if cweek = "21" or "23" or "25" then%>

You could determine the even/odd weeks like this:
<% if cweek mod 2 = 0 then %>

If cweek mod 2 is 0, then you're in an even week; else, you're in an odd week.

When you say "display the code", though, do you mean the HTML between the ASP parts? If so, you're probably going to need to do some document.write code within the ASP to ensure the right stuff displays at the right week result.

Author

Commented:
Ok, do I need to define cweek mod anywhere or is that a terms that's "understood" by VB Script and all I have to do is just write that line of code?

"Display the code" means that I've got that part done, I just didn't want to write it all out.

Basically I've got two versions of the same code, but want one to display on even numbered weeks and the ohter on odd.

Author

Commented:
Ok, that did work.  I did a little test and it worked fine.

<% 
ctime = FormatDateTime(Time,vbShortTime)
cday = WeekDayName(WeekDay(Date))
cweek = DatePart("ww", Now)
%>
<% if cweek mod 2 = 0 then %> 
This will display the week 2 menus
<% else %>
This will display the week 1 menus
<% end if %>

Open in new window

Author

Commented:
Just what I needed!

Commented:
"mod" is a VB operator (like +, -, *, and /). This operator name is short for "modulus" - a math term for the remainder part of a division. Using it in VB (or VBscript) will return the value of the remainder of a division.

If you say (10 / 5), for example, the answer is 2, and the remainder is equal to zero, right? Use 'mod' to replace the '/' - 10 mod 5 - and it will return the remainder of zero instead of the result of the division (which, of course, would be 2). (10 / 3), for example, is 3 with a remainder of 1. So, (10 mod 3) will give you 1. (10 / 6) is 1 with a remainder of 4. (10 mod 6), then, gives you .... 4. I'm sure you get the idea now. :) The mod operator will always return zero if the numbers on either side go into each other evenly. So, if cweek is equal to an even-numbered week, (cweek mod 2) will always return zero. If cweek is equal to an odd-numbered week, then (cweek mod 2) will always be greater than zero. (The parens are just for clarity, by the way - you don't have to use them in your code.)

Good luck with your ASP/VBscript adventures!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial