2012-01-16 82 views
0

我有8個布爾變量,我需要能夠爲每個布爾值爲真的電子郵件字符串添加電子郵件。如果不寫一百萬條if語句,我不知道如何去做。下面是一些我有:循環布爾變量

if bIsBlue then 
     strEmailTo = strSalesEmail 
     strEmailTo = strEmailTo & ", " & varBlueGrp 
    End if 
    if bIsRed then 
     strEmailTo = strSalesEmail 
     strEmailTo = strEmailTo & ", " & varRedGrp 
    End if 
    if bIsGreen then 
     strEmailTo = strSalesEmail 
     strEmailTo = strEmailTo & ", " & varGreenGrp 
    End if 
    if bIsBrown then 
     strEmailTo = strSalesEmail 
     strEmailTo = strEmailTo & ", " & varBrownGrp        
    End if 
    if bIsBlue and bIsRed then 
     strEmailTo = strSalesEmail 
     strEmailTo = strEmailTo & ", " & varBlueGrp & ", " & varRedGrp 
    End if 
    if bIsBlue and bIsGreen then 
     strEmailTo = strSalesEmail 
     strEmailTo = strEmailTo & ", " & varBlueGrp & ", " & varGreenGrp 
    End if 
+0

你需要的是查找表。對於每個鍵(Color),您應該存儲一個電子郵件組值。至少,你應該使用switch語句。 http://msdn.microsoft.com/en-us/library/dft2z9yf(v=vs.80).aspx –

+0

另請參閱http://msdn.microsoft.com/en-us/library/xfhwa508.aspx –

+1

謝謝一堆! – user1152145

回答

1

我建議你讓那些布爾變量的數組,然後遍歷扔的如此 ü可以對所有的變量一個更快的訪問。