This should work though I haven't tested it since I don't have a CSV file of your colors.
You establish a class that contains members R, G, B and ID, ensuring it has = and <> operators.
Then you use the ability of Lists to do this kind of work for you.
Imports System.Math
Imports System.IO
Public Class Something
Private ColorList As List(Of ExampleRGB) = New List(Of ExampleRGB)
Private MatchedIDs As List(Of ExampleRGB) = New List(Of ExampleRGB)
Private RGBConstraint As ExampleRGB
Public Sub Main()
ReadColors()
SearchColors()
End Sub
Private Sub ReadColors()
Dim filename As String = "colors.csv"
Dim StringColorArray() As String
Dim ColorString As String
If File.Exists(filename) Then
Dim tmpstream As StreamReader = File.OpenText(filename)
StringColorArray = tmpstream.ReadToEnd().Split({Environment.NewLine}, StringSplitOptions.None)
Dim tmpExampleRGB As ExampleRGB
For Each ColorString In StringColorArray
tmpExampleRGB = New ExampleRGB(ColorString)
ColorList.Add(tmpExampleRGB)
Next
End If
End Sub
Private Sub SearchColors()
RGBConstraint = New ExampleRGB("10,20,30,100")
MatchedIDs = ColorList.FindAll(AddressOf MatchIDs)
End Sub
Private Function MatchIDs(ByVal testExampleRGB As ExampleRGB) As Boolean
If testExampleRGB = RGBConstraint Then
Return True
Else
Return False
End If
End Function
End Class
Public Class ExampleRGB
Implements IEquatable(Of ExampleRGB)
Private _R As Integer
Private _G As Integer
Private _B As Integer
Private _id As Integer
Private _colorString As String
Sub New(ColorString As String)
Dim items() As String
items = ColorString.Split(New String() {","}, StringSplitOptions.None)
Me.Red = Integer.Parse(items(0))
Me.Green = Integer.Parse(items(1))
Me.Blue = Integer.Parse(items(2))
Me.ID = Integer.Parse(items(3))
End Sub
Sub New()
Me.Red = 0
Me.Green = 0
Me.Blue = 0
Me.ID = 0
End Sub
Public Property Red As Integer
Get
Return Me._R
End Get
Set(value As Integer)
If Me._R <> value Then
value =
Me._R = value
End If
End Set
End Property
Public Property Green As Integer
Get
Return Me._G
End Get
Set(value As Integer)
If Me._G <> value Then
value = Min(value, 255)
value = Max(0, value)
Me._G = value
End If
End Set
End Property
Public Property Blue As Integer
Get
Return Me._B
End Get
Set(value As Integer)
If Me._B <> value Then
value = Min(value, 255)
value = Max(0, value)
Me._B = value
End If
End Set
End Property
Public Property ID As Integer
Get
Return Me._id
End Get
Set(value As Integer)
If Me._id <> value Then
Me._id = value
End If
End Set
End Property
Public Overloads Function Equals(ByVal testObject As ExampleRGB) As Boolean Implements IEquatable(Of MadBager.Scratch.ExampleRGB).Equals
Return testObject = Me
End Function
Public Shared Operator =(ByVal object1 As ExampleRGB, ByVal object2 As ExampleRGB) As Boolean
Return object1.Red = object2.Red And
object1.Green = object2.Green And
object1.Blue = object2.Blue
End Operator
Public Shared Operator <>(ByVal object1 As ExampleRGB, ByVal object2 As ExampleRGB) As Boolean
Return Not object1 = object2
End Operator
End Class