[AccessD] Is there a preferred style

Joe Hecht jmhla at earthlink.net
Wed Mar 23 00:03:00 CST 2005


Did not even think of select case.
Thanks for reminder

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Tuesday, March 22, 2005 9:34 PM
To: Access Developers discussion and problemsolving
Subject: Re: [AccessD] Is there a preferred style

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


-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list