Too many IF statements

Results 1 to 3 of 3

Thread: Too many IF statements

  1. #1
    Join Date
    Dec 1969

    Default Too many IF statements

    I am currently re doing a site created buy someone else. I need to keep the same function, but it appears the current way the process is being done has 60 if statements. Now it works, but there are several problems. 1. Thats way too many If statements, and 2. The problems the If statements are handling will soon have to be increased.<BR><BR>The code I am re working goes like this. There is a loop of 4 different possiblities for a site to be based on a 7 day timeframe. Today begins week 1 site that is shown, next monday begins week 2, and so on. When week four occurs it returns back to week 1...repeating til the end of time. The way the previous web developer wrote this is in if statements. He subtracted todays date from a base date and divided that number by 7, then wrote if statements based on his answer. So if his answer was 1 he would show week 1 if it was 6, he would show week 2. This works fine except the loops is basically hard coded and the only way it seems to work is if I would keep adding more if statements to handle the division answer. I need suggestions on how to reduce this the least amount of code and if statements as possible.

  2. #2
    Join Date
    Dec 1969

    Default RE: Too many IF statements

    Calc what wheek it is Based on the Dates<BR><BR>Then<BR><BR>Select Case WeekNum<BR>Case 1<BR> &#039;Do whatever for week 1<BR>Case 2<BR> etc etc<BR>Case 3<BR> &#039;blah blah<BR>Case 4<BR> &#039;whatever<BR>Case Else<BR> &#039;Unknown week number<BR>End Select<BR>

  3. #3
    Join Date
    Dec 1969

    Default initial Idea

    You should seperate the problem into several tasks.. One function to handle your 4 possible situations... You can use a case statement for that. You actually want to write a function which returns the week in which the date occurs. This function would definitely use weekday() and MOD to determine the week. Determine the day of week for the first Day of the month and proceed to calculate the correct value. If you Case statement to too hard to manage, break up the process into several functions so that you can manage each of them more easily.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts