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

if then statements vs Case statements Help

Status
Not open for further replies.

zishan619

Programmer
May 28, 2003
284
MX
I have an array of (30,3).
I do not want to do too many if then statements. Basically they are 30 time codes and 2 weeks of hours for the timecode.
So currently I am doing the following:
Week(x,0)=rsWeek("TimeCodeID")
Week(x,1)=rsWeek("dblHoursW1")
Week(x,2)=rsWeek("dblHoursW2")

if Week(x,0)= 1 then
strDataScript = strDataScript & "Document.All(""REGLabel1_" & iPageCount & "_" & iRowCount & "_20"").innerhtml = """ & Week(x,1) & """" & vbcrlf
strDataScript = strDataScript & "Document.All(""REGLabel2_" & iPageCount & "_" & iRowCount & "_21"").innerhtml = """ & Week(x,2) & """" & vbcrlf
End if

if Week(x,0)=2 then
strDataScript = strDataScript & "Document.All(""OTLabel1_" & iPageCount & "_" & iRowCount & "_22"").innerhtml = """ & Week(x,1) & """" & vbcrlf
strDataScript = strDataScript & "Document.All(""OTLabel2_" & iPageCount & "_" & iRowCount & "_23"").innerhtml = """ & Week(x,2) & """" & vbcrlf
End if

if Week(x,0)=4 then
strDataScript = strDataScript & "Document.All(""BHPLabel1_" & iPageCount & "_" & iRowCount & "_24"").innerhtml = """ & Week(x,1) & """" & vbcrlf
strDataScript = strDataScript & "Document.All(""BHPLabel2_" & iPageCount & "_" & iRowCount & "_25"").innerhtml = """ & Week(x,2) & """" & vbcrlf
End if
is there a better way to do this instead of writing 30 if then statements.
Thanks
 
Is there any reason you couldn't do this with a for statement

Code:
for x = 1 to 30
   strDataScript = strDataScript & "Document.All(""REGLabel1_" & iPageCount & "_" & iRowCount & "_20"").innerhtml = """ & Week(x,1) & """" & vbcrlf
        strDataScript = strDataScript & "Document.All(""REGLabel2_" & iPageCount & "_" & iRowCount & "_21"").innerhtml = """ & Week(x,2) & """" & vbcrlf
next x

John
 
Or maybe:
Code:
    Week(x,0)=rsWeek("TimeCodeID")
    Week(x,1)=rsWeek("dblHoursW1")
    Week(x,2)=rsWeek("dblHoursW2")

    strDataScript = strDataScript _
                  & "Document.All(""REGLabel1_" _
                  & iPageCount & "_" & iRowCount _
                  & "_" & CStr(18 + 2 * Week(x, 0)) _
                  & """).innerhtml = """ & Week(x,1) _
                  & """" & vbCrLf
    strDataScript = strDataScript _
                  & "Document.All(""REGLabel2_" _
                  & iPageCount & "_" & iRowCount _
                  & "_" & CStr(19 + 2 * Week(x, 0)) _
                  & """).innerhtml = """ & Week(x,2) _
                  & """" & vbCrLf
 
While the above replies are best, here's another variation in case you didn't have sequential numbers to test:
Code:
If Week(x,0)= 1 Then
   ...
Elseif Week(x,0)= 2 Then
   ...
Elseif Week(x,0)= 3 Then
   ...
Elseif Week(x,0)= 4 Then
   ...
Else
   ...
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top