Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through a string 2

Status
Not open for further replies.

egolds

MIS
Aug 29, 2001
105
0
0
US
I have a page with 7 checkboxes, one for each day of the week. To avoid having a session variable for each day of the week that I need to check for on or off I have each checkbox named "NOTWORK" and the value is (M,T,W,TH,F,SA,SU) so if someone checks Monday Wednesday and Friday the value of Session("NotWork") is equal to M,W,F.

I need a way to loop through this string so that if the user comes back to this page the checkboxes will be checked.

In Each checkbox I have the following:

<%NotWorkCheck(&quot;M&quot;)%> where M would be in Monday, T in Tuesday....

and the function NotWorkCheck is as follows:

Function NotWorkCheck(Day)
dim arrDays(7),x
arrDays=Session(&quot;NotWork&quot;)
for x = 1 to 7
if arrDays(x) = Day then respose.write(&quot; checked&quot;)
Next
End Function

The page is erroring when it attempts to assign Session(&quot;NotWork&quot;) to arrDays giving a type mismatch error.
Is there a way to do this or should I go back to 7 variables for each day?
 
Try to use Split function.
Whend u receive the Request(&quot;NOTWORK&quot;) in the asp page u get all the values separated by &quot;,&quot; (ie &quot;M,W,F&quot;) therefor u need to split this string to acess his separate values more easylly:

days=Split(Session(&quot;NOTWORK&quot;),&quot;,&quot;)
if u have Session(&quot;NOTWORK&quot;)=&quot;M,W,F&quot;
then days(0)=&quot;M&quot;, days(1)=&quot;W&quot;,days(2)=&quot;F&quot;. ________
George, M
 
Worked like a charm. Thanks for the info on the Split function something to keep in my bag of tricks.

Eric
 
Using InStr to check the contents of the session variable for each day would also work.

If instr(Session(&quot;NotWork&quot;), &quot;M&quot;) then
turn on Monday check box
end if
if instr(Session(&quot;NotWork&quot;), &quot;T&quot;) then
turn on Tuesday check box
end if

Only problem is that searching for &quot;T&quot; for tuesday would also hit on &quot;TH&quot; for thursday. Either change &quot;TH&quot; to something unique or delimit the fields and search for &quot;,T,&quot; where &quot;,&quot; is the delimiter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top