Only the last IF...

RTRD

Member
Joined
Jan 25, 2012
Messages
10
Location
Oslo, Norway
Programming Experience
1-3
Only the last IF is "rendering", why? And how do I fix it? :)

VB.NET:
'------------------------------------------        '        RAL Colors
        '------------------------------------------
        If HexBoxText = "" Then
            'do nothing
        Else
            If HexBox.Text = "#BEDB7F" Then
                RALBox.Text = "1000"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#C2B078" Then
                RALBox.Text = "1001"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#C6A664" Then
                RALBox.Text = "1002"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#E5BE01" Then
                RALBox.Text = "1003"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#E5BE01" Then
                RALBox.Text = "1003"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#E5BE01" Then
                RALBox.Text = "1003"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#CDA434" Then
                RALBox.Text = "1004"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#A98307" Then
                RALBox.Text = "1005"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#E4A010" Then
                RALBox.Text = "1006"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#DC9D00" Then
                RALBox.Text = "1007"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#8A6642" Then
                RALBox.Text = "1011"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#C7B446" Then
                RALBox.Text = "1012"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#EAE6CA" Then
                RALBox.Text = "1013"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#E1CC4F" Then
                RALBox.Text = "1014"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#E6D690" Then
                RALBox.Text = "1015"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#EDFF21" Then
                RALBox.Text = "1016"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#F5D033" Then
                RALBox.Text = "1017"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#F8F32B" Then
                RALBox.Text = "1018"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#9E9764" Then
                RALBox.Text = "1019"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#999950" Then
                RALBox.Text = "1020"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#F3DA0B" Then
                RALBox.Text = "1021"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#FAD201" Then
                RALBox.Text = "1023"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#AEA04B" Then
                RALBox.Text = "1024"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#FFFF00" Then
                RALBox.Text = "1026"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#9D9101" Then
                RALBox.Text = "1027"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#F4A900" Then
                RALBox.Text = "1028"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#D6AE01" Then
                RALBox.Text = "1032"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#F3A505" Then
                RALBox.Text = "1033"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#EFA94A" Then
                RALBox.Text = "1034"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#6A5D4D" Then
                RALBox.Text = "1035"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#705335" Then
                RALBox.Text = "1036"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#F39F18" Then
                RALBox.Text = "1037"
            Else
                RALBox.Text = ""
            End If
            'NEXT COLOR
            If HexBox.Text = "#FFFFFF" Then
                RALBox.Text = "9010"
            Else
                RALBox.Text = ""
            End If
        End If
        '------------------------------------------
        '        RAL Colors END
        '------------------------------------------
 
why not scratch the else part and make it like this,

VB.NET:
If Not HexBoxText = "" Then
    
     'all the other If Else statements here

End If
 
The reason is because in each of your If Then Else statements you're clearing it out if it does not match, which means unless 'HexBox.Text' equals "#FFFFFF" then 'RALBox.Text' will always be blank.

This is a perfect example of using a select case statement. Here's a few of them done for you:
VB.NET:
Select Case HexBox.Text.Trim
  Case "#BEDB7F" : RALBox.Text = "1002"
  Case "#C2B078" : RALBox.Text = "1001"
  Case "#C6A664" : RALBox.Text = "1002"
  Case "#E5BE01" : RALBox.Text = "1003"
  Case Else : RALBox.Clear() 'None of the above matched, so clear the RALBox
End Select
This way it's much more clear as to what's going on.
 
The reason is because in each of your If Then Else statements you're clearing it out if it does not match, which means unless 'HexBox.Text' equals "#FFFFFF" then 'RALBox.Text' will always be blank.

This is a perfect example of using a select case statement. Here's a few of them done for you:
VB.NET:
Select Case HexBox.Text.Trim
  Case "#BEDB7F" : RALBox.Text = "1002"
  Case "#C2B078" : RALBox.Text = "1001"
  Case "#C6A664" : RALBox.Text = "1002"
  Case "#E5BE01" : RALBox.Text = "1003"
  Case Else : RALBox.Clear() 'None of the above matched, so clear the RALBox
End Select
This way it's much more clear as to what's going on.

How do I change only one letter with the "Case"?
Like a translator thing. Ex: E to e

But still translates rest of the text in the box...
 
How do I change only one letter with the "Case"?
Like a translator thing. Ex: E to e

But still translates rest of the text in the box...
One way to do it would be to change this line:
Select Case HexBox.Text.Trim

To:
Select Case HexBox.Text.Trim.ToUpper

The .ToUpper will translate all letters into uppercase, you could do .ToLower if you wanted all of them to be lower case.
 
Back
Top