Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21719

Little Boxes (on a hillside)---Trying to Color Code based on Values

$
0
0
Okay....gave up.....am trying to simply color code three textboxes (text1(0), text1(1), and text1(2) base upon their value:
If one of them has a value more than the other two, make the BG green.
If one of them as the min value of all three, make the BG Red.
For the one that falls in the middle (if there is one), make the BG Yellow.
If any TIE for the top value (either 2 or 3 of them), make those BG's green.
If any two TIE for the min value, make both of them yellow.
I'm doing this on the textbox change event so as I type in a value, the three textboxes change BG color.

Here is my long drawn out code trying to do a simple (??) task......and it doesn't work correctly. Any suggestions? (to include starting over with a different concept?)

Code:

Private Sub Text1_Change(Index As Integer)
  Dim a(3) As Integer
  Dim i_min, i_max, max, min, i As Integer
  a(0) = Val(Trim(Text1(0).Text))
  a(1) = Val(Trim(Text1(1).Text))
  a(2) = Val(Trim(Text1(2).Text))
i_min = LBound(a)
i_max = UBound(a)
min = 32767 ' for short int
For i = i_min To i_max - 1
If a(i) < min Then min = a(i)
Next
Dim myMinValue, myMaxValue As Integer
myMinValue = min
max = i_min                      '<-- assign this the i_min  value
min = i_min
For i = i_min To i_max
    If a(i) > max Then max = a(i)
    If a(i) < min Then min = a(i)
Next
Dim x As Integer
myMaxValue = max
Select Case Index
Case 0
      If Trim(Text1(0).Text) = Trim(Str(myMaxValue)) Then
          Text1(0).BackColor = vbGreen
          Text1(1).BackColor = vbYellow    'set other two to yellow
          Text1(2).BackColor = vbYellow
          If Trim(Text1(1).Text) = Trim(Str(myMinValue)) Then  'find min value, set to red
              Text1(1).BackColor = vbRed
              If Trim(Text1(1).Text) = Trim(Text1(2).Text) Then
                  Text1(2).BackColor = vbRed
              Else
                  Text1(2).BackColor = vbYellow
              End If
          Else
              Text1(2).BackColor = vbRed
          End If
      End If
Case 1
      If Trim(Text1(1).Text) = Trim(Str(myMaxValue)) Then
          Text1(1).BackColor = vbGreen
          Text1(0).BackColor = vbYellow    'set other two to yellow
          Text1(2).BackColor = vbYellow
          If Trim(Text1(0).Text) = Trim(Str(myMinValue)) Then  'find min value, set to red
              Text1(0).BackColor = vbRed
              If Trim(Text1(0).Text) = Trim(Text1(2).Text) Then
                  Text1(2).BackColor = vbRed
              Else
                  Text1(2).BackColor = vbYellow
              End If
          Else
              Text1(2).BackColor = vbRed
          End If
      End If
Case 2
      If Trim(Text1(2).Text) = Trim(Str(myMaxValue)) Then
          Text1(2).BackColor = vbGreen
          Text1(0).BackColor = vbYellow    'set other two to yellow
          Text1(1).BackColor = vbYellow
          If Trim(Text1(0).Text) = Trim(Str(myMinValue)) Then  'find min value, set to red
              Text1(0).BackColor = vbRed
              If Trim(Text1(0).Text) = Trim(Text1(1).Text) Then
                  Text1(1).BackColor = vbRed
              Else
                  Text1(0).BackColor = vbYellow
              End If
          Else
              Text1(0).BackColor = vbRed
          End If
      End If
End Select
      If Trim(Text1(2).Text) = Trim(Text1(1).Text) Then
          If Trim(Text1(1).Text) = Trim(Text1(0).Text) Then
              For x = 0 To 2
                  Text1(x).BackColor = vbGreen
              Next x
          End If
      End If
End Sub


Viewing all articles
Browse latest Browse all 21719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>