Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want a behaviour such such as when textfile loaded in richtextbox then every line should get splitted into words into textbox/richtextbox.

What I have tried:

if suppose i load textfile into richtextbox and suppose "n" number lines of textfile are as :

line 1 = abcd 1235 xyz pqr

line 2 = 12345 set xyzfdsfsdf

line 3 = rytytryrtytr

There are 'n' number of lines in a richtextbox.

then line by line the line should get splitted into word by word in textbox/richtextbox and when save is clicked then all splitted words should get joined as it were series earlier.
Posted
Updated 20-Jun-19 1:11am
Comments
Maciej Los 20-Jun-19 6:03am    
What have you tried?
shaileshshinde 20-Jun-19 6:45am    
Dim dataArry() As String = RichTextBox2.Text.Split("&")
TextBox1.Text = dataArry(0)
TextBox2.Text = dataArry(1)
If CheckBox1.Checked = False Then
TextBox1.Text = ""
TextBox2.Text = ""

End If
Maciej Los 20-Jun-19 7:06am    
You're on the right track! Only small changes are needed:
Dim dataArray() As String = RichTextBox2.Lines(selecttedline).Split(" ")
Dim i As Integer = 1
For Each s As String In dataArray
    Dim txt As TextBox = DirectCast(Me.Controls("TextBox" & i), TextBox)
    txt.Text = s
    i+=1
Next
[no name] 26-Feb-23 14:40pm    
Dim dataArray() As String = RichTextBox2.Lines(selecttedline).Split(" ")
Dim i As Integer = 1
For Each s As String In dataArray
Dim txt As TextBox = DirectCast(Me.Controls("TextBox" & i), TextBox)
txt.Text = s
i+=1
Next

1 solution

Try this:
VB.NET
Dim dataArray() As String = RichTextBox2.Lines(selectedline).Split(" ")
Dim i As Integer = 1
For Each s As String In dataArray
    Dim txt As TextBox = DirectCast(Me.Controls("TextBox" & i), TextBox)
    txt.Text = s
    i+=1
Next


Where selectedline is currently selected line a RichTexBox1. You already know how to get this (previous question[^]).
 
Share this answer
 
Comments
shaileshshinde 20-Jun-19 7:31am    
i tried this:

Private Sub SelectLine(direction As Direction)

Dim lineindex As Integer = currentline + direction
If lineindex < 0 Then
'this is the first line!
Exit Sub
End If

If lineindex > RichTextBox1.Lines.Count - 1 Then
'this is the last line!
Exit Sub
End If

Dim searchedtext = RichTextBox1.Lines(lineindex)
Dim indexofText As Integer = RichTextBox1.Find(searchedtext, RichTextBoxFinds.MatchCase)
RichTextBox1.Select(indexofText, searchedtext.Length)
RichTextBox1.Focus()

End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

Dim dataArray() As String = RichTextBox2.Lines(SelectLine).Split(" ")
Dim i As Integer = 1
For Each s As String In dataArray
Dim txt As TextBox = DirectCast(Me.Controls("TextBox" & i), TextBox)
txt.Text = s
i += 1
Next
End Sub


but i am getting below errors:
Error 1:
Severity Code Description Project File Line Suppression State
Error BC30269 'Private Sub SelectLine(direction As Form1.Direction)' has multiple definitions with identical signatures. RichtextBoxLineUpDown C:\Users\OM\Downloads\RichtextBoxLineUpDown\RichtextBoxLineUpDown\RichtextBoxLineUpDown\Form1.vb 18 Active

Error 2:
Severity Code Description Project File Line Suppression State
Error BC30521 Overload resolution failed because no accessible 'SelectLine' is most specific for these arguments:
'Private Sub SelectLine(direction As Form1.Direction)': Not most specific.
'Private Sub SelectLine(direction As Form1.Direction)': Not most specific. RichtextBoxLineUpDown C:\Users\OM\Downloads\RichtextBoxLineUpDown\RichtextBoxLineUpDown\RichtextBoxLineUpDown\Form1.vb 11 Active


Error 3:
Severity Code Description Project File Line Suppression State
Error BC30521 Overload resolution failed because no accessible 'SelectLine' is most specific for these arguments:
'Private Sub SelectLine(direction As Form1.Direction)': Not most specific.
'Private Sub SelectLine(direction As Form1.Direction)': Not most specific. RichtextBoxLineUpDown C:\Users\OM\Downloads\RichtextBoxLineUpDown\RichtextBoxLineUpDown\RichtextBoxLineUpDown\Form1.vb 15 Active


Error 4:
Severity Code Description Project File Line Suppression State
Error BC30516 Overload resolution failed because no accessible 'SelectLine' accepts this number of arguments. RichtextBoxLineUpDown C:\Users\OM\Downloads\RichtextBoxLineUpDown\RichtextBoxLineUpDown\RichtextBoxLineUpDown\Form1.vb 85 Active
shaileshshinde 22-Jun-19 2:46am    
@Maciej can i get reply from your side for my above issue to get it resolved?
Maciej Los 23-Jun-19 6:26am    
Dear @shaileshshinde,
I've resolved your issue and provided complete example. Your other issue does not belong to originally posted question.
BTW: i'm not a code-writer on demand. If you would like to complete your issues by other person, you have to hire freelancer.
Note that i'm helping people for free in my free time. So, do not expect that i resolve all your issues.
Cheers
Maciej
shaileshshinde 23-Jun-19 6:48am    
Ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900