Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a lines suppose:

abcde 12385 8755 87878988 dsfgfgfdg
12345 211323 fgfgfdgf 544555 dfghghh weewrerr opopppiopoi weewrewrwe
xyz
587964

and when "current word" is displayed in one textbox3 then "previous word" should be displayed in textbox4 and "next word" from line should be displayed in textbox5

What I have tried:

Due to below working code i am able to get the current word only.

Dim somestring2() As String
somestring2 = RichTextBox2.Text.Split(" ")
Dim sh As New mb.ShowMessagebox
For i = 0 To somestring2.Length - 1


textbox3.Text = somestring2(i)


sh.ShowBox(somestring2(i), mb.MStyle.ok, mb.FStyle.Keys, "Single Word Window")

Next

is there any solution for this?
Posted
Updated 3-Jul-19 22:06pm
v3
Comments
Maciej Los 4-Jul-19 3:21am    
As far as i see only one line with 4 "words" in it.
shaileshshinde 4-Jul-19 4:36am    
the richtextboxlineupanddown code was given by you.the same i am using.but now i have managed to split words and show it in messagebox as well as textbox.

but now i want next word and previous word to get showed in different textboxes.

not getting the idea for that method to show next and previous word in different textboxes.
shaileshshinde 5-Jul-19 2:36am    
any solution for my above query?
shaileshshinde 8-Jul-19 3:14am    
can you please help me with this solution?

1 solution

Please, read my comment to the question first.

Check this:
VB.NET
Dim singleline As String = "abcde 12345 xyz 587964"
Dim words As String() = singleline.Split(New String(){" "}, StringSplitOptions.RemoveEmptyEntries)

For Each word As String In words
	Console.WriteLine(word)
Next


Result:
abcde
12345
xyz
587964


[EDIT]

If you would like to get next/previous word, you have to write method similar to SelectLine provided by me in this solution: Move to next & back line in richtextbox via button click[^]


[EDIT#2]

On the top of Form1 module:
VB.NET
Dim currentword As Integer = 0

Public Enum Direction
    Up = -1
    Down = 1
End Enum


Events for next/previous buttons:
VB.NET
Private Sub BtnNextWord_Click(sender As Object, e As EventArgs) Handles BtnNextWord.Click
    DisplayWords(Direction.Down)
End Sub

Private Sub BtnPrevWord_Click(sender As Object, e As EventArgs) Handles BtnPrevWord.Click
    DisplayWords(Direction.Up)
End Sub


Procedure to display words:
VB.NET
Private Sub DisplayWords(direction As Direction)
    Dim words As String() = Me.RichTextBox1.Lines _
                            .SelectMany(Function(line) line.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)) _
                            .ToArray()

    Me.TxtCurrentWord.Text = words(currentword)
    Me.TxtPreviousWord.Text = If(currentword > 0, words(currentword - 1), Nothing)
    Me.TxtNextWord.Text = If(currentword < words.Count - 1, words(currentword + 1), Nothing)

    currentword += direction
    If currentword < 0 Then currentword = 0
    If currentword > words.Count - 1 Then currentword = words.Count - 1

End Sub
 
Share this answer
 
v4
Comments
shaileshshinde 4-Jul-19 4:15am    
@Maciej not getting the idea for that method.
Maciej Los 8-Jul-19 9:40am    
Check out updated answer.
shaileshshinde 9-Jul-19 0:45am    
You are superb maciej.guru
shaileshshinde 9-Jul-19 0:48am    
But I have one more query regarding this method and other richboxlineupdown code given by you.
How the final file will be saved.as i checked for lineupdown i saw only one line is getting saved and googled also.i did not get logic for saving lineupdown and this wordupdown as a one text/doc file in order as they were in original text/word file
Maciej Los 9-Jul-19 5:18am    
It should be something Luke this:
File.WriteAllLines("C:\rtb.txt", RichTextBox1.Lines)

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