Not sure how to write code for multiple IF statement in Defect

  • Questions
  • Not sure how to write code for multiple IF statement in Defect
Question ID: 107310
0
0

Not sure how to write code for multiple IF statement in Defect

Marked as spam
Posted by (Questions: 122, Answers: 3)
Asked on December 13, 2016 8:52 pm
8 views
Answers (1)
0
Private answer

There are two options for doing this:

1) You can use an OR operator in your IF statement to check for multiple conditions such as in this example (the underscore after the OR is to allow the statement to use multple rows).

Sub Bug_FieldChange(FieldName)
On Error Resume Next

If FieldName= ''BG_STATUS'' Then
If Bug_Fields.Field(''BG_STATUS'').value= ''Ready for Testing'' OR _
Bug_Fields.Field(''BG_STATUS'').value= ''Rejected'' OR _
Bug_Fields.Field(''BG_STATUS'').value= ''Requirements Review'' OR _
Bug_Fields.Field(''BG_STATUS'').value= ''SME verification''
Then
Bug_Fields(''BG_USER_05'').IsRequired=True
Else
Bug_Fields(''BG_USER_05'').IsRequired=False
End If
End If

End Sub

2) You can build this into a Select statement instead. This would be useful if you anticipate adding future conditions.

Sub Bug_FieldChange(FieldName)
On Error Resume Next

If FieldName= ''BG_STATUS'' Then

Select Bug_Fields.Field(''BG_STATUS'').value
Case ''Ready for Testing''
Bug_Fields.Field(''BG_USER_05'').IsRequired=True
Case ''Rejected''
Bug_Fields.Field(''BG_USER_05'').IsRequired=True
Case ''Requirements Review''
Bug_Fields.Field(''BG_USER_05'').IsRequired=True
Case ''SME verification''
Bug_Fields.Field(''BG_USER_05'').IsRequired=True
End Select

End If

End Sub

Marked as spam
Posted by (Questions: 3, Answers: 168)
Answered on December 13, 2016 8:58 pm