Choosing which for loop based on If boolean condition

Why not set up a variable for the amount of times to loop based on your true or false?

 Dim Ti(0 To 3) As String
  Ti(1) = "Temperature"
  Ti(2) = "Outside Temperature"
  Ti(3) = "Inside Temperature"

  Dim Tj(0 To 3) As String
  Tj(1) = "Temperature"
  Tj(2) = "Outside Temperature"
  Tj(3) = "Inside Temperature"

  Flag1 = 0
  Flag2 = 0
  TCSflag = 0
  upperLimit = 3
  If onlyflag = False Then
     upperLimit = 2
  EndIf

            For i = 1 To upperLimit
                TCChannel = Me.Controls.Item("TCSDropDown" & i).Text
                If TCChannel = "Not Available" Then
                ElseIf TCChannel = "Select Temp" Then
                    TCSflag = TCSflag + 1
                    MsgBox("Please select a temp for" & " " & Ti(i), vbCritical, "Error")
                    Exit For
                Else
                    If InStr(1, TCChannel, "Type 1") Then
                        Flag1 = 1
                    End If
                    If InStr(1, TCChannel, "Type 2") Then
                        Flag2 = 1
                    End If

                    For j = 1 To upperLimit

                        If Ti(i) <> Tj(j) Then
                            TCChannel1 = Me.Controls.Item("TCSDropDown" & j).Text
                            If TCChannel1 = "Not Available" Then
                            Else
                                If TCChannel = TCChannel1 Then
                                    MsgBox("You selected the same temp for both " & Ti(i) & " and " & Tj(j), vbCritical, "Conflicting Temp Selection!")
                                    TCSflag = TCSflag + 1
                                    Exit For
                                End If
                            End If
                        End If
                    Next

                    If TCSflag >= 1 Then
                        Exit For
                    End If
                End If
            Next

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top