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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping my code to cut down on bloat 1

Status
Not open for further replies.

solo7

Technical User
Mar 14, 2001
243
NO
I have the following code which works fine and does exactly as I want it to. However this code applies to one command button and there are 14 - I would like to cut down on the bloat and try to get this into a loop. The code below works for all of my buttons Command00 to Command13 and list00 to list13 when the value of WeekDay(Date + (0) ,1) is incremented by 1, going from zero (example below) up to the value of 13.
The final result shows the comming 14 days in 'Mon', Tue', 'Wed' format with the 'Sat' and 'Sun' buttons disabled.

Code:
Dim IntDayOfWeek

List00_Label.innerText= FormatDateTime(Date + (0), 2)
IntDayOfWeek= WeekDay(Date + (0) ,1)
	If IntDayOfWeek=7 or IntDayOfWeek=1 then
	Command00.innerText= WeekDayName(IntDayOfWeek,True)
	Command00.disabled = True
	else
	Command00.innerText= WeekDayName(IntDayOfWeek,True)
	end If

solo7 [thumbsup2]
 
Hello solo7,

This is how you can use execute statement.
Code:
for i=0 to 13
    if i<10 then si="0"&cstr(i) else si=cstr(i)
    execute "List" & si & "_Label.innerText= FormatDateTime(Date + (0), 2)"
    IntDayOfWeek= WeekDay(Date + (0) ,1)
    If IntDayOfWeek=7 or IntDayOfWeek=1 then
        execute "Command" & si & ".innerText= WeekDayName(IntDayOfWeek,True)"
        execute "Command" & si & ".disabled = True"
    else
        execute "Command" & si & ".innerText= WeekDayName(IntDayOfWeek,True)"
    end If
next
regards - tsuji
 
Thanks tsuji,
that's just what the doctor ordered. I had played with the COMMAND statement but didn't get as far as using the inverted commas - Many thanks

solo7 [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top