Hi guys sorry I have no code written because I'm not sure where to start.
I have a simple program with a single line richtextbox. I have buttons for all the numbers and characters in a deck of cards. For example buttons Joker A 2 3 4 5 6 7 8 9 10 J Q K and also a ? button which I want to treat as a word as well.
When I press a button it adds the corresponding num or letter to the richtextbox with a space following right after it.
What I am trying to achieve is when the word count is greater then 7 the last 7 words in the line of text will be highlighted. Which in this case except for the number 10 they are all 1 letter words
Does anyone have the expertise to know how to achieve this?
By the way my code sucks I know because I am just learning but everything works so far just need that feature to work. But here is all my code
Thanks in advance
Code:Imports System.Text.RegularExpressions Public Class HF_Helper Public resultsArray(0) As String Public results As Integer Private Sub Joker_Click(sender As Object, e As EventArgs) Handles Joker.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "JK " MyBox.SelectionColor = Color.DodgerBlue MyBox.AppendText("J ") End Sub Private Sub Wild2_Click(sender As Object, e As EventArgs) Handles Wild2.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "2 " MyBox.SelectionColor = Color.DarkOrange MyBox.AppendText("2 ") End Sub Private Sub Red3_Click(sender As Object, e As EventArgs) Handles Red3.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "R3 " MyBox.SelectionColor = Color.Red MyBox.AppendText("3 ") End Sub Private Sub Black3_Click(sender As Object, e As EventArgs) Handles Black3.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "3 " MyBox.SelectionColor = Color.Black MyBox.AppendText("3 ") End Sub Private Sub Card4_Click(sender As Object, e As EventArgs) Handles Card4.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "4 " MyBox.SelectionColor = Color.Black MyBox.AppendText("4 ") End Sub Private Sub Card5_Click(sender As Object, e As EventArgs) Handles Card5.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "5 " MyBox.SelectionColor = Color.Black MyBox.AppendText("5 ") End Sub Private Sub Card6_Click(sender As Object, e As EventArgs) Handles Card6.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "6 " MyBox.SelectionColor = Color.Black MyBox.AppendText("6 ") End Sub Private Sub Card7_Click(sender As Object, e As EventArgs) Handles Card7.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "7 " MyBox.SelectionColor = Color.Black MyBox.AppendText("7 ") End Sub Private Sub Card8_Click(sender As Object, e As EventArgs) Handles Card8.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "8 " MyBox.SelectionColor = Color.Black MyBox.AppendText("8 ") End Sub Private Sub Card9_Click(sender As Object, e As EventArgs) Handles Card9.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "9 " MyBox.SelectionColor = Color.Black MyBox.AppendText("9 ") End Sub Private Sub Card10_Click(sender As Object, e As EventArgs) Handles Card10.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "10 " MyBox.SelectionColor = Color.Black MyBox.AppendText("10 ") End Sub Private Sub CardJ_Click(sender As Object, e As EventArgs) Handles CardJ.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "J " MyBox.SelectionColor = Color.Black MyBox.AppendText("J ") End Sub Private Sub CardQ_Click(sender As Object, e As EventArgs) Handles CardQ.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "Q " MyBox.SelectionColor = Color.Black MyBox.AppendText("Q ") End Sub Private Sub CardK_Click(sender As Object, e As EventArgs) Handles CardK.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "K " MyBox.SelectionColor = Color.Black MyBox.AppendText("K ") End Sub Private Sub CardA_Click(sender As Object, e As EventArgs) Handles CardA.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "A " MyBox.SelectionColor = Color.Black MyBox.AppendText("A ") End Sub Private Sub CardQuest_Click(sender As Object, e As EventArgs) Handles CardQuest.Click results = resultsArray.Count - 1 ReDim Preserve resultsArray(results + 1) resultsArray(results) = "? " MyBox.SelectionColor = Color.DarkOliveGreen MyBox.AppendText("? ") End Sub Private Sub MyBox_TextChanged(sender As Object, e As EventArgs) Handles MyBox.TextChanged MyBox.SelectionAlignment = HorizontalAlignment.Left End Sub Private Sub UndoButton_Click(sender As Object, e As EventArgs) Handles UndoButton.Click If resultsArray.Count <= 1 Then MyBox.Lines = MyBox.Lines.Take(MyBox.Lines.Count - 1).ToArray ReDim resultsArray(0) Else MyBox.Lines = MyBox.Lines.Take(MyBox.Lines.Count - 1).ToArray ReDim Preserve resultsArray(resultsArray.Count - 2) End If Dim i As Integer For i = 0 To resultsArray.Count - 2 If resultsArray(i) = "JK " Then MyBox.SelectionColor = Color.DodgerBlue MyBox.AppendText("J ") ElseIf resultsArray(i) = "R3 " Then MyBox.SelectionColor = Color.Red MyBox.AppendText("3 ") ElseIf resultsArray(i) = "? " Then MyBox.SelectionColor = Color.DarkOliveGreen MyBox.AppendText("? ") ElseIf resultsArray(i) = "2 " Then MyBox.SelectionColor = Color.DarkOrange MyBox.AppendText("2 ") Else MyBox.SelectionColor = Color.Black MyBox.AppendText(resultsArray(i)) End If 'MyBox.AppendText(resultsArray(i)) Next i End Sub Private Sub HF_Helper_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.TopMost = True End Sub Private Sub CLR_Click(sender As Object, e As EventArgs) Handles CLR.Click MyBox.Lines = MyBox.Lines.Take(MyBox.Lines.Count - 1).ToArray ReDim resultsArray(0) End Sub Private Sub UP_Click(sender As Object, e As EventArgs) Handles UP.Click MyBox.Lines = MyBox.Lines.Take(MyBox.Lines.Count - 1).ToArray If resultsArray.Count - 1 >= 7 Then ReDim Preserve resultsArray(resultsArray.Count - 8) Else ReDim Preserve resultsArray(resultsArray.Count - resultsArray.Count) End If Dim i As Integer For i = 0 To resultsArray.Count - 2 If resultsArray(i) = "JK " Then MyBox.SelectionColor = Color.DodgerBlue MyBox.AppendText("J ") ElseIf resultsArray(i) = "R3 " Then MyBox.SelectionColor = Color.Red MyBox.AppendText("3 ") ElseIf resultsArray(i) = "? " Then MyBox.SelectionColor = Color.DarkOliveGreen MyBox.AppendText("? ") ElseIf resultsArray(i) = "2 " Then MyBox.SelectionColor = Color.DarkOrange MyBox.AppendText("2 ") Else MyBox.SelectionColor = Color.Black MyBox.AppendText(resultsArray(i)) End If Next i End Sub Private Sub Close_Click(sender As Object, e As EventArgs) Handles Close.Click Application.Exit() End Sub Private Sub Rollup_Click(sender As Object, e As EventArgs) Handles Rollup.Click If Me.FormBorderStyle = FormBorderStyle.FixedToolWindow Then Me.FormBorderStyle = FormBorderStyle.None Else Me.FormBorderStyle = FormBorderStyle.FixedToolWindow End If End Sub End Class




Reply With Quote
