Change Color a Textboxes from the Lower of the Highest [on hold]












0














I have 2 codes to change the color to Textbox, and unfortunately none of them work. What's wrong here? Why the code is not good. Every time I try the code, it tells me there are no variables. The first code changes the color to Textbox if there is a value between 1 and 7, and the second changes the value in ascending order from the lowest to the highest and assigns a corresponding color.



Code 1:



Public Class TextBoxColors
Private ColorTable As Dictionary(Of String, Color) = New Dictionary(Of String, Color)()
Public Sub New()
ColorTable.Add("1", Color.Red)
ColorTable.Add("2", Color.Aqua)
ColorTable.Add("3", Color.Chocolate)
ColorTable.Add("4", Color.BlanchedAlmond)
ColorTable.Add("5", Color.BurlyWood)
ColorTable.Add("6", Color.BlueViolet)
ColorTable.Add("7", Color.DarkBlue)
End Sub
Public Function GetColor(ColorMap As String) As Color
Return If(ColorTable.Keys.Contains(ColorMap), ColorTable(ColorMap), Color.White)
End Function
End Class

Private txtColor As TextBoxColors = New TextBoxColors()

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each txtDraw As TextBox In Me.Controls.OfType(Of TextBox).Where(Function(txt) txt.Name.StartsWith("txtDraw"))
AddHandler txtDraw.TextChanged,
Sub()
If Not String.IsNullOrEmpty(txtDraw.Text) Then
txtDraw.BackColor = txtColor.GetColor(txtDraw.Text)
End If
End Sub
Next
End Sub


Code 2: This 2nd code must be changed based on my text box, which starts with SumtxtDraw



 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FillColorList()
End Sub

Private Sub ColorTextBoxes()
FillTextBoxList(16, 23)
Dim SortedList As List(Of TextBox) = SortList()
Dim index As Integer
For Each txt As TextBox In SortedList
txt.BackColor = lstColor(index)
index += 1
Next
End Sub

Private Sub FillColorList()
lstColor.Add(Color.Red) 'for lowest number
lstColor.Add(Color.BlanchedAlmond)
lstColor.Add(Color.PaleGreen)
lstColor.Add(Color.Chartreuse)
lstColor.Add(Color.CadetBlue)
lstColor.Add(Color.Orange)
lstColor.Add(Color.DarkMagenta)
lstColor.Add(Color.Violet) 'for highest number
End Sub

Private Sub FillTextBoxList(StartNumber As Integer, EndNumber As Integer)
lstTextBox.Clear()
For suffix = StartNumber To EndNumber
lstTextBox.Add(DirectCast(Controls("TextBox" & suffix.ToString), TextBox))
Next
End Sub

Private Function SortList() As List(Of TextBox)
Dim orderedList = From txt In lstTextBox Order By CInt(txt.Text) Descending Select txt '$"{scorer.Score} - {scorer.Name}"
Dim SortedList As List(Of TextBox) = orderedList.ToList
Return SortedList
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ColorTextBoxes()
End Sub









share|improve this question







New contributor




Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Jamal 16 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.


















    0














    I have 2 codes to change the color to Textbox, and unfortunately none of them work. What's wrong here? Why the code is not good. Every time I try the code, it tells me there are no variables. The first code changes the color to Textbox if there is a value between 1 and 7, and the second changes the value in ascending order from the lowest to the highest and assigns a corresponding color.



    Code 1:



    Public Class TextBoxColors
    Private ColorTable As Dictionary(Of String, Color) = New Dictionary(Of String, Color)()
    Public Sub New()
    ColorTable.Add("1", Color.Red)
    ColorTable.Add("2", Color.Aqua)
    ColorTable.Add("3", Color.Chocolate)
    ColorTable.Add("4", Color.BlanchedAlmond)
    ColorTable.Add("5", Color.BurlyWood)
    ColorTable.Add("6", Color.BlueViolet)
    ColorTable.Add("7", Color.DarkBlue)
    End Sub
    Public Function GetColor(ColorMap As String) As Color
    Return If(ColorTable.Keys.Contains(ColorMap), ColorTable(ColorMap), Color.White)
    End Function
    End Class

    Private txtColor As TextBoxColors = New TextBoxColors()

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    For Each txtDraw As TextBox In Me.Controls.OfType(Of TextBox).Where(Function(txt) txt.Name.StartsWith("txtDraw"))
    AddHandler txtDraw.TextChanged,
    Sub()
    If Not String.IsNullOrEmpty(txtDraw.Text) Then
    txtDraw.BackColor = txtColor.GetColor(txtDraw.Text)
    End If
    End Sub
    Next
    End Sub


    Code 2: This 2nd code must be changed based on my text box, which starts with SumtxtDraw



     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    FillColorList()
    End Sub

    Private Sub ColorTextBoxes()
    FillTextBoxList(16, 23)
    Dim SortedList As List(Of TextBox) = SortList()
    Dim index As Integer
    For Each txt As TextBox In SortedList
    txt.BackColor = lstColor(index)
    index += 1
    Next
    End Sub

    Private Sub FillColorList()
    lstColor.Add(Color.Red) 'for lowest number
    lstColor.Add(Color.BlanchedAlmond)
    lstColor.Add(Color.PaleGreen)
    lstColor.Add(Color.Chartreuse)
    lstColor.Add(Color.CadetBlue)
    lstColor.Add(Color.Orange)
    lstColor.Add(Color.DarkMagenta)
    lstColor.Add(Color.Violet) 'for highest number
    End Sub

    Private Sub FillTextBoxList(StartNumber As Integer, EndNumber As Integer)
    lstTextBox.Clear()
    For suffix = StartNumber To EndNumber
    lstTextBox.Add(DirectCast(Controls("TextBox" & suffix.ToString), TextBox))
    Next
    End Sub

    Private Function SortList() As List(Of TextBox)
    Dim orderedList = From txt In lstTextBox Order By CInt(txt.Text) Descending Select txt '$"{scorer.Score} - {scorer.Name}"
    Dim SortedList As List(Of TextBox) = orderedList.ToList
    Return SortedList
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    ColorTextBoxes()
    End Sub









    share|improve this question







    New contributor




    Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    put on hold as off-topic by Jamal 16 mins ago


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

    If this question can be reworded to fit the rules in the help center, please edit the question.
















      0












      0








      0







      I have 2 codes to change the color to Textbox, and unfortunately none of them work. What's wrong here? Why the code is not good. Every time I try the code, it tells me there are no variables. The first code changes the color to Textbox if there is a value between 1 and 7, and the second changes the value in ascending order from the lowest to the highest and assigns a corresponding color.



      Code 1:



      Public Class TextBoxColors
      Private ColorTable As Dictionary(Of String, Color) = New Dictionary(Of String, Color)()
      Public Sub New()
      ColorTable.Add("1", Color.Red)
      ColorTable.Add("2", Color.Aqua)
      ColorTable.Add("3", Color.Chocolate)
      ColorTable.Add("4", Color.BlanchedAlmond)
      ColorTable.Add("5", Color.BurlyWood)
      ColorTable.Add("6", Color.BlueViolet)
      ColorTable.Add("7", Color.DarkBlue)
      End Sub
      Public Function GetColor(ColorMap As String) As Color
      Return If(ColorTable.Keys.Contains(ColorMap), ColorTable(ColorMap), Color.White)
      End Function
      End Class

      Private txtColor As TextBoxColors = New TextBoxColors()

      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      For Each txtDraw As TextBox In Me.Controls.OfType(Of TextBox).Where(Function(txt) txt.Name.StartsWith("txtDraw"))
      AddHandler txtDraw.TextChanged,
      Sub()
      If Not String.IsNullOrEmpty(txtDraw.Text) Then
      txtDraw.BackColor = txtColor.GetColor(txtDraw.Text)
      End If
      End Sub
      Next
      End Sub


      Code 2: This 2nd code must be changed based on my text box, which starts with SumtxtDraw



       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      FillColorList()
      End Sub

      Private Sub ColorTextBoxes()
      FillTextBoxList(16, 23)
      Dim SortedList As List(Of TextBox) = SortList()
      Dim index As Integer
      For Each txt As TextBox In SortedList
      txt.BackColor = lstColor(index)
      index += 1
      Next
      End Sub

      Private Sub FillColorList()
      lstColor.Add(Color.Red) 'for lowest number
      lstColor.Add(Color.BlanchedAlmond)
      lstColor.Add(Color.PaleGreen)
      lstColor.Add(Color.Chartreuse)
      lstColor.Add(Color.CadetBlue)
      lstColor.Add(Color.Orange)
      lstColor.Add(Color.DarkMagenta)
      lstColor.Add(Color.Violet) 'for highest number
      End Sub

      Private Sub FillTextBoxList(StartNumber As Integer, EndNumber As Integer)
      lstTextBox.Clear()
      For suffix = StartNumber To EndNumber
      lstTextBox.Add(DirectCast(Controls("TextBox" & suffix.ToString), TextBox))
      Next
      End Sub

      Private Function SortList() As List(Of TextBox)
      Dim orderedList = From txt In lstTextBox Order By CInt(txt.Text) Descending Select txt '$"{scorer.Score} - {scorer.Name}"
      Dim SortedList As List(Of TextBox) = orderedList.ToList
      Return SortedList
      End Function

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      ColorTextBoxes()
      End Sub









      share|improve this question







      New contributor




      Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have 2 codes to change the color to Textbox, and unfortunately none of them work. What's wrong here? Why the code is not good. Every time I try the code, it tells me there are no variables. The first code changes the color to Textbox if there is a value between 1 and 7, and the second changes the value in ascending order from the lowest to the highest and assigns a corresponding color.



      Code 1:



      Public Class TextBoxColors
      Private ColorTable As Dictionary(Of String, Color) = New Dictionary(Of String, Color)()
      Public Sub New()
      ColorTable.Add("1", Color.Red)
      ColorTable.Add("2", Color.Aqua)
      ColorTable.Add("3", Color.Chocolate)
      ColorTable.Add("4", Color.BlanchedAlmond)
      ColorTable.Add("5", Color.BurlyWood)
      ColorTable.Add("6", Color.BlueViolet)
      ColorTable.Add("7", Color.DarkBlue)
      End Sub
      Public Function GetColor(ColorMap As String) As Color
      Return If(ColorTable.Keys.Contains(ColorMap), ColorTable(ColorMap), Color.White)
      End Function
      End Class

      Private txtColor As TextBoxColors = New TextBoxColors()

      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      For Each txtDraw As TextBox In Me.Controls.OfType(Of TextBox).Where(Function(txt) txt.Name.StartsWith("txtDraw"))
      AddHandler txtDraw.TextChanged,
      Sub()
      If Not String.IsNullOrEmpty(txtDraw.Text) Then
      txtDraw.BackColor = txtColor.GetColor(txtDraw.Text)
      End If
      End Sub
      Next
      End Sub


      Code 2: This 2nd code must be changed based on my text box, which starts with SumtxtDraw



       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      FillColorList()
      End Sub

      Private Sub ColorTextBoxes()
      FillTextBoxList(16, 23)
      Dim SortedList As List(Of TextBox) = SortList()
      Dim index As Integer
      For Each txt As TextBox In SortedList
      txt.BackColor = lstColor(index)
      index += 1
      Next
      End Sub

      Private Sub FillColorList()
      lstColor.Add(Color.Red) 'for lowest number
      lstColor.Add(Color.BlanchedAlmond)
      lstColor.Add(Color.PaleGreen)
      lstColor.Add(Color.Chartreuse)
      lstColor.Add(Color.CadetBlue)
      lstColor.Add(Color.Orange)
      lstColor.Add(Color.DarkMagenta)
      lstColor.Add(Color.Violet) 'for highest number
      End Sub

      Private Sub FillTextBoxList(StartNumber As Integer, EndNumber As Integer)
      lstTextBox.Clear()
      For suffix = StartNumber To EndNumber
      lstTextBox.Add(DirectCast(Controls("TextBox" & suffix.ToString), TextBox))
      Next
      End Sub

      Private Function SortList() As List(Of TextBox)
      Dim orderedList = From txt In lstTextBox Order By CInt(txt.Text) Descending Select txt '$"{scorer.Score} - {scorer.Name}"
      Dim SortedList As List(Of TextBox) = orderedList.ToList
      Return SortedList
      End Function

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      ColorTextBoxes()
      End Sub






      beginner






      share|improve this question







      New contributor




      Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 17 mins ago









      Lucian Dorin

      1




      1




      New contributor




      Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Lucian Dorin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      put on hold as off-topic by Jamal 16 mins ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.




      put on hold as off-topic by Jamal 16 mins ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.



























          active

          oldest

          votes






















          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'