3 Replies Latest reply on Jan 22, 2019 8:07 PM by TimCarmichael

    If statement not working

    Topper1

      I am having a issue with this.

      Sub test()

       

      Dim T As Trend

      Dim f As TrendFormat

      Dim s As Double

      Dim c As Double

      Dim i As String

      Dim d As String

      Dim s2 As Double

      Dim i2 As Double

       

       

      Set T = ThisDisplay.Trend1

      Set f = T.GetFormat

      c = ThisDisplay.Value1.GetValue(d, st)

      s = ThisDisplay.Text1.Contents

      d = ThisDisplay.Value2.GetValue(d, st)

      i = ThisDisplay.Text2.Contents

      s2 = ThisDisplay.Text4.Contents

      i2 = ThisDisplay.Text5.Contents

        

         

         

          If d = "DENT" Then

          'changing using dent specs off corn type

              If c < s Or c > i Then f.Elements(pbBackGround).Color = RGB(255, 255, 0) And f.Elements(pbPen1).Color = RGB(255, 0, 255) Else f.Elements(pbBackGround).Color = RGB(0, 255, 0) And f.Elements(pbPen1).Color = RGB(0, 0, 255)

          Else

          'changeing using waxy specs off corn type

              If c >= s2 Or c <= i2 Then f.Elements(pbBackGround).Color = RGB(255, 255, 0) And f.Elements(pbPen1).Color = RGB(255, 0, 0) Else f.Elements(pbBackGround).Color = RGB(0, 255, 0) And f.Elements(pbPen1).Color = RGB(0, 0, 255)

          End If

       

          T.SetFormat f

       

      Set T = Nothing

       

       

      End Sub

      The issue is the first then section is causing my trend to go black and not changing pen color.

        • Re: If statement not working
          TimCarmichael

          It looks like you are trying to have two colors changed in the section:
          If c < s Or c > i Then f.Elements(pbBackGround).Color = RGB(255, 255, 0) And f.Elements(pbPen1).Color = RGB(255, 0, 255) Else f.Elements(pbBackGround).Color = RGB(0, 255, 0) And f.Elements(pbPen1).Color = RGB(0, 0, 255)

           

          However, you aren't performing two actions, only one:

              f.Elements(pbBackGround).Color = RGB(255, 255, 0) And f.Elements(pbPen1).Color = RGB(255, 0, 255)

          This is taking RGB(255, 255, 0) and doing a logical and on f.Elements(pbPen1).Color = RGB(255, 0, 255)

           

          You may need to duplicate the statement to provide two actions:

          If c < s Or c > i Then f.Elements(pbBackGround).Color = RGB(255, 255, 0) Else f.Elements(pbBackGround).Color = RGB(0, 255, 0)

          If c < s Or c > i Then f.Elements(pbPen1).Color = RGB(255, 0, 255) Else f.Elements(pbPen1).Color = RGB(0, 0, 255)

           

          Then perform a like action on your 'else' statement to split it into two pieces as well.