asked on # VB Script array

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?

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,vbShor

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?

VB ScriptASP

Log in or sign up to see answer

Become an EE member today7-DAY FREE TRIAL

Members can start a 7-Day Free trial then enjoy unlimited access to the platform

or

Learn why we charge membership fees

We get it - no one likes a content blocker. Take one extra minute and find out why we block content.

Not exactly the question you had in mind?

Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.

ask a question
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 %>
```

Just what I needed!

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst

William Peck

"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!

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!

"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.