473,584 Members | 2,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Turn IfThen mess into loop!

OK Ive got a huge amount of If Then statements that Im sure can be stripped
way down to a simple loop or two but Im not familiar enough with them to
know where to start.
Basically this is a truck scheduling application which builds a layer for
each schedule of each truck from Monday thru Sunday.
Below are the statements I have so far and I need to go up to 20 trucks. I
think you'll be able to tell what Im trying to do.
You'll notice from 3 trucks on, the layer widths are the same.

Can someone guide me on how I can convert this to a loop to cut down the
amount of code?

Thanks in advance!

<% '############## SET DIV WIDTH DETERMINED BY TRUCK COUNT
If myRS("TruckTota l") = 1 then
response.write "132"
ElseIf myRS("TruckTota l") = 2 then
response.write "67"
ElseIf myRS("TruckTota l") = 3 then
response.write "35"
ElseIf myRS("TruckTota l") > 3 then
response.write "35"
End If
%>px;
<%
'############## Grab Day, Truck # and position div horizontally
#############
'############## ############### ####### 1 Truck ###
'###Monday
If myRS("TruckTota l") = 1 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 173px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 304px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 435px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 566px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 697px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 828px;"
end if
end if
end if

'############## ############## 2 Trucks ###
'###Monday
If myRS("TruckTota l") = 2 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 108px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 174px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 240px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 306px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 372px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 438px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 504px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 570px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 636px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 702px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 768px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 834px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 900px;"
end if
end if
end if

'############## ########### 3 Trucks ###
'###Monday
If myRS("TruckTota l") = 3 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 144px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 178px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 212px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 280px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 314px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 348px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:382px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 416px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 484px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 518px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 552px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 586px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 620px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 688px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 722px;"
end if
end if
end if

'############## ########### 4 Trucks ###
'###Monday
If myRS("TruckTota l") = 4 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 144px;"

end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 178px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 212px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 280px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 314px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 348px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 382px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 416px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:484px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 518px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 552px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 586px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 620px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 688px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 722px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 756px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 790px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 824px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 858px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 892px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 926px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 960px;"
end if
end if
end if

'############## ########### 5 Trucks ###
'###Monday
If myRS("TruckTota l") = 5 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 144px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 178px;"

end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 212px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 280px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 314px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 348px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 382px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 416px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 484px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 518px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 552px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:586px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left:6208p x;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 688px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 722px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 756px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 790px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 824px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 858px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 892px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 926px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 960px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 994px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 1028px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 1062px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 1096px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 1130px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 1164px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 1198px;"
end if
end if
end if
'######## AND SO ON TILL 20 TRUCKS REACHED
Jul 22 '05 #1
3 1284
Look at the Case statement

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Jake" <sp******@allte l.net> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
OK Ive got a huge amount of If Then statements that Im sure can be
stripped way down to a simple loop or two but Im not familiar enough with
them to know where to start.
Basically this is a truck scheduling application which builds a layer for
each schedule of each truck from Monday thru Sunday.
Below are the statements I have so far and I need to go up to 20 trucks. I
think you'll be able to tell what Im trying to do.
You'll notice from 3 trucks on, the layer widths are the same.

Can someone guide me on how I can convert this to a loop to cut down the
amount of code?

Thanks in advance!

<% '############## SET DIV WIDTH DETERMINED BY TRUCK COUNT
If myRS("TruckTota l") = 1 then
response.write "132"
ElseIf myRS("TruckTota l") = 2 then
response.write "67"
ElseIf myRS("TruckTota l") = 3 then
response.write "35"
ElseIf myRS("TruckTota l") > 3 then
response.write "35"
End If
%>px;
<%
'############## Grab Day, Truck # and position div horizontally
#############
'############## ############### ####### 1 Truck ###
'###Monday
If myRS("TruckTota l") = 1 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 173px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 304px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 435px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 566px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 697px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 828px;"
end if
end if
end if

'############## ############## 2 Trucks ###
'###Monday
If myRS("TruckTota l") = 2 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 108px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 174px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 240px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 306px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 372px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 438px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 504px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 570px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 636px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 702px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 768px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 834px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 900px;"
end if
end if
end if

'############## ########### 3 Trucks ###
'###Monday
If myRS("TruckTota l") = 3 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 144px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 178px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 212px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 280px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 314px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 348px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:382px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 416px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 484px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 518px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 552px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 586px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 620px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 688px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 722px;"
end if
end if
end if

'############## ########### 4 Trucks ###
'###Monday
If myRS("TruckTota l") = 4 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 144px;"

end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 178px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 212px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 280px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 314px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 348px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 382px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 416px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:484px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 518px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 552px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 586px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 620px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 688px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 722px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 756px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 790px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 824px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 858px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 892px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 926px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 960px;"
end if
end if
end if

'############## ########### 5 Trucks ###
'###Monday
If myRS("TruckTota l") = 5 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 144px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 178px;"

end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 212px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 280px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 314px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 348px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 382px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 416px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 484px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 518px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 552px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:586px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left:6208p x;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 688px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 722px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 756px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 790px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 824px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 858px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 892px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 926px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 960px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 994px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 1028px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 1062px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 1096px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 1130px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 1164px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 1198px;"
end if
end if
end if
'######## AND SO ON TILL 20 TRUCKS REACHED

Jul 22 '05 #2
"Jake" <sp******@allte l.net> wrote in message
news:#M******** ******@TK2MSFTN GP15.phx.gbl...
OK Ive got a huge amount of If Then statements that Im sure can be stripped way down to a simple loop or two but Im not familiar enough with them to
know where to start.
Basically this is a truck scheduling application which builds a layer for
each schedule of each truck from Monday thru Sunday.
Below are the statements I have so far and I need to go up to 20 trucks. I
think you'll be able to tell what Im trying to do.
You'll notice from 3 trucks on, the layer widths are the same.

Can someone guide me on how I can convert this to a loop to cut down the
amount of code?

Thanks in advance!

<% '############## SET DIV WIDTH DETERMINED BY TRUCK COUNT
If myRS("TruckTota l") = 1 then
response.write "132"
ElseIf myRS("TruckTota l") = 2 then
response.write "67"
ElseIf myRS("TruckTota l") = 3 then
response.write "35"
ElseIf myRS("TruckTota l") > 3 then
response.write "35"
End If
%>px;
<%
'############## Grab Day, Truck # and position div horizontally
#############
'############## ############### ####### 1 Truck ###
'###Monday
If myRS("TruckTota l") = 1 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 173px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 304px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 435px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 566px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 697px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 828px;"
end if
end if
end if

'############## ############## 2 Trucks ###
'###Monday
If myRS("TruckTota l") = 2 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 108px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 174px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 240px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 306px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 372px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 438px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 504px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 570px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 636px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 702px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 768px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 834px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 900px;"
end if
end if
end if

'############## ########### 3 Trucks ###
'###Monday
If myRS("TruckTota l") = 3 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 144px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 178px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 212px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 280px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 314px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 348px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:382px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 416px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 484px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 518px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 552px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 586px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 620px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 688px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 722px;"
end if
end if
end if

'############## ########### 4 Trucks ###
'###Monday
If myRS("TruckTota l") = 4 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 144px;"

end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 178px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 212px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 280px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 314px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 348px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 382px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 416px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:484px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 518px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 552px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 586px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 620px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 688px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 722px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 756px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 790px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 824px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 858px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 892px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 926px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 960px;"
end if
end if
end if

'############## ########### 5 Trucks ###
'###Monday
If myRS("TruckTota l") = 5 then
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 1 then
If myRS2("TruckInd ex")="1" then
response.write "left: 42px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 76px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 110px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 144px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 178px;"

end if
end if
'###Tuesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 2 then
If myRS2("TruckInd ex")="1" then
response.write "left: 212px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 246px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 280px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 314px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 348px;"
end if
end if
'###Wednesday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 3 then
If myRS2("TruckInd ex")="1" then
response.write "left: 382px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 416px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 450px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 484px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 518px;"
end if
end if
'###Thursday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 4 then
If myRS2("TruckInd ex")="1" then
response.write "left: 552px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left:586px ;"
elseif myRS2("TruckInd ex")="3" then
response.write "left:6208p x;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 654px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 688px;"
end if
end if
'###Friday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 5 then
If myRS2("TruckInd ex")="1" then
response.write "left: 722px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 756px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 790px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 824px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 858px;"
end if
end if
'###Saturday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 6 then
If myRS2("TruckInd ex")="1" then
response.write "left: 892px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 926px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 960px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 994px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 1028px;"
end if
end if
'###Sunday
If WeekDay(myRS2(" Sched_Date"), VBMonday) = 7 then
If myRS2("TruckInd ex")="1" then
response.write "left: 1062px;"
elseif myRS2("TruckInd ex")="2" then
response.write "left: 1096px;"
elseif myRS2("TruckInd ex")="3" then
response.write "left: 1130px;"
elseif myRS2("TruckInd ex")="4" then
response.write "left: 1164px;"
elseif myRS2("TruckInd ex")="5" then
response.write "left: 1198px;"
end if
end if
end if
'######## AND SO ON TILL 20 TRUCKS REACHED


Can you boil it down to a matrix (spreadsheet)?

Perhaps by "TruckTotal " and "TruckIndex "; for example,

1.1 = 42,173,304,435, 566,697,828

2.1 = 42,174,306,438, 570,702,834
2.2 = 108,240,372,504 ,636,768,900

etc.

(It would be nice if 1.1 = 2.1 etc.)
Also, "left:6208p x;" should probably be "left:620px ;"
Jul 22 '05 #3

Jake wrote:
OK Ive got a huge amount of If Then statements that Im sure can be stripped way down to a simple loop or two but Im not familiar enough with them to know where to start.
Basically this is a truck scheduling application which builds a layer for each schedule of each truck from Monday thru Sunday.
Below are the statements I have so far and I need to go up to 20 trucks. I think you'll be able to tell what Im trying to do.
You'll notice from 3 trucks on, the layer widths are the same.


I would put all of this data into a database and check it against that.
Have a range of values in the database for TruckTotal, and you'd have
divwidth, etc.

Then do a select based on your input parameters.

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1835
by: Khen Chzakuv | last post by:
Fred wants an e-commerce website. He commissions Jo, a freelancer who is a good web designer and knows a little about programming (from an extremely sub-standard university), to create the website for him. Jo sets to work creating lots of pretty HTML pages with calls to as-yet-unwritten PHP scripts mixed in with the HTML and Javascript. To...
15
2732
by: Buck Rogers | last post by:
Hi guys! Task 1: Write a program which presents a menu with 5 options. The 5th option quits the program. Each option should execute a system command using system(). Below is my humble offering. =================================================== #include <stdio.h> #include <stdlib.h>
23
3254
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
17
1964
by: VM | last post by:
In my Windows app, I'm running a batch process that's composed of a FOR loop that'll run 15,000 times (datatable row count), copy cthe data of each row -3 fields- to a struct, and send the strct to an external method (using DLLImport). The problem is that the processing speed is very inconsistent- it may run very FAST during certain points...
4
1227
by: carl.manaster | last post by:
Hi, Group, I prefer indenting braces with their block, thus: public int Foo() .....{ .....Bar(); .....}
8
1455
by: bmlclemson08 | last post by:
Hey if anyone could I need to find out how to write a program that will read in any number of integers, including none, and determine which is the largest integer. The part i can't figure out is getting the program to read any number of integers. Any ideas at all would be wonderful. here's the code for what i have so far. #include...
8
3789
by: sabirah | last post by:
My code does not seem to be working properly... The game is b/w a human and the computer. The computer always goes first. The computer chooses the first corner in the first turn. in the comp's 2nd turn, it chooses the opposite corner if possible, if that corner is not availabe, the computer chooses randomly. In the computers next...
9
1896
by: TF | last post by:
Hello all, I made a ASP.NET 2.0 site that shows possible "recipes" for paint colors stored in an access dbase. Basically, 1000 colors are stored with specific RGB values in separate columns. A user sees all the colors listed on the page with hyperlinks that open the "mixes" page. The mixes page goes through each record, compares it with...
1
1825
by: trav4 | last post by:
I have an assignment for school and I am new to programming. For the assignment I need to make a survey with at least 4 choices that uses 2 arrays. It must be done in a console application. How do I make it loop and count/store the responses until the user enters "N" at strAnswer=Console.readline? Where/what loop would I use? ...
0
7829
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8189
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7940
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8198
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5379
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1438
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.