2014-01-28 267 views
0

請幫助,下面是我在Visual Basic中的代碼。for循環中多個if語句

我的for循環不會去第二個if條件。它只是檢查第一個。我在這裏錯過了什麼?

謝謝!

If Not dsMarketingOrdIDs Is Nothing Then 
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1 
     If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then 
      If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then 
       blnKbAuthorXtremeSupport = True 
      End If 
      If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then 
       If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then 
        blnKbAuthorXtremePortal = True 

       End If 
      End If 
     End If 
    Next 
End If 

回答

1

應該是這樣的:

If Not dsMarketingOrdIDs Is Nothing Then 
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1 
     If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then 
      If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then 
       blnKbAuthorXtremeSupport = True 
      End If 
     End If 
     If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then 
      If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then 
       blnKbAuthorXtremePortal = True 
      End If 
     End If 
    Next 
End If 

或者更簡單:

If Not dsMarketingOrdIDs Is Nothing Then 
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1 
     blnKbAuthorXtremePortal = Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") _ 
      AndAlso (dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 OrElse dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152) 
    Next 
End If 
0

您是否嘗試過的其他人,如果?

If Not dsMarketingOrdIDs Is Nothing Then 
    For i = 0 To dsMarketingOrdIDs.Tables(0).Rows.Count - 1 
     If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 5 Then 
      If Not objALUtil.CheckPermission("KBAUTHORXTREMESUPPORT") Then 
       blnKbAuthorXtremeSupport = True 
      Else If dtMarketingOrdIDs.Rows(i)("marketing_org_id") = 152 Then 
       If Not objALUtil.CheckPermission("KBAUTHORXTREMEPORTAL") Then 
        blnKbAuthorXtremePortal = True 
       End If 
      End If 
     End If 
    Next 
End If 

另外,您的MARKETING_ORG_ID如何能一次成爲5和152?

dtMarketingOrdIDs.Rows(I)( 「marketing_org_id」)= 5個

dtMarketingOrdIDs.Rows(I)( 「marketing_org_id」)= 152