Stuart McLachlan
stuart at lexacorp.com.pg
Tue Mar 22 23:34:17 CST 2005
On 22 Mar 2005 at 21:12, Joe Hecht wrote: > Working alone is the pits. > > I have three tests to set the value of a text box. What is considered to be > good coding practice? > I try to avoid nesting "If"s, they can get very messy. Assuming the cases are mutually exclusive, I find this sort of thing much easier to follow: Select Case Switch(TestOne = True, 1, TestTwo = True, 2, TestThree = True, 3) Case 1 dosomething Case 2 dosomethingelse Case 3 doathirdthing Case Else MsgBox "Nothing is true" End Select If they are not mutually exclusive, you could use a bitmask Flag = 0 If testOne = true then flag = flag +1 If testTwo = true then flag = flag +2 If testThree = true then flag = flag +4 Select Case flag Case 0 'Nothing is true Case 1 'testone is true Case 2 'testtwo is true Case 3 'testone and testtwo are true ....... -- Stuart