Vera,
Don't know why your code does not work, but just
a couple comments on your code fragment here...
First, almost every time we have resorted to
using List.SetWeight it turned out that we had a
poor design structure, and once we restructured
the design it eliminated the need for
List.SetWeight and solved a host of other lurking
problems as well. So I urge you to first take a
serious look at your design structure.
Next, when we did use List.SetWeight, we
absolutely had to execute a List.Reset, otherwise
the List ignored our .SetWeight changes. So if
your code does not work with the List.Reset
command in place, then your code has other problems.
And since you must do the List.Reset for either
branch of the If...Then...ElseIf, then you may as
well pull it out from within the branches and put
it after the whole If...Then...ElseIf block.
Finally, what happens if TriggerValue < 0 or
TriggerValue >= 7? As it stands, in this case
your code will simply leave the List intact. Is
this what you meant? Perhaps you think it
impossible for TriggerValue to ever take on
values outside of 0-6, but good coding practice
requires that you either include a final Else to
handle outliers or at least add a comment to
explain what you mean the code to do.
So just as an exercise, here is your code
fragement again (keeping your TriggerValue
variable because I do not want to get into that
issue, using "<=" instead of "<" just because I
think that makes the intent clearer, and adding a
Const to get rid of one "magic number"; hmm, on
further thought I restructured this to pull the
common inner loops out of the main loop, etc.):
Const TriggerValueMax as Integer = 6
Dim nLevel as Integer
Dim TriggerValue as Integer, TriggerValueToRun as Integer
' Assign TriggerValueToRun based on NewTriggerValue:
If (NewTriggerValue = 0) Then
TriggerValueToRun = 0
ElseIf ((1 <= NewTriggerValue) AND _
(NewTriggerValue <= TriggerValueMax)) Then
TriggerValueToRun = 1
Else MsgBox "NewTriggerValue " & NewTriggerValue _
& "out of range! Please contact programmer."
End If
' Now set List level weights according to match between TriggerValue &
' TriggerValueToRun:
For nLevel = 1 to DesignList.Size
TriggerValue = DesignList.GetAttrib(nLevel,"Trigger")
If TriggerValue = TriggerValueToRun Then
DesignList.SetWeight nLevel, 1
Else DesignList.SetWeight nLevel, 0
End If
Next nLevel
DesignList.Reset
Or just for fun, let's do this with a Select Case:
Const TriggerValueMax as Integer = 6
Dim nLevel as Integer
Dim TriggerValue as Integer, TriggerValueToRun as Integer
' Assign TriggerValueToRun based on NewTriggerValue:
Select Case NewTriggerValue
Case 0
TriggerValueToRun = 0
Case 1 to 6
TriggerValueToRun = 1
Case Else
MsgBox "NewTriggerValue " & NewTriggerValue _
& "out of range! Please contact programmer."
End Select
' Now set List level weights according to match between TriggerValue &
' TriggerValueToRun:
For nLevel = 1 to DesignList.Size
TriggerValue = DesignList.GetAttrib(nLevel,"Trigger")
If TriggerValue = TriggerValueToRun Then
DesignList.SetWeight nLevel, 1
Else DesignList.SetWeight nLevel, 0
End If
Next nLevel
DesignList.Reset
-- David McFarlane, Professional Faultfinder