vb.net Line numbering in multi line Rich Text Box if line starts with specific conditionVB.NET Syntax Highlighting in a Rich Text BoxHover tooltip on specific words in rich text box?convert csv data to DataTable in VB.netHow to op-en file and view in a rich text box using vb.net?VB.NET - Auto fill Rich Text Box in WebBrowser?Count Specific lines in a text file (that start with a number)Rich Text Box VB.NET Line By Line Stop and auto?VB.Net Form Controls For Formatting A Rich Text BoxOpening File Rich Text Box (VB.NET)VB.NET progressbar based on cmd output

Alternative classical explanation of the Stern-Gerlach Experiment?

how to create an executable file for an AppleScript?

How to draw pentagram-like shape in Latex?

Referring to a character in 3rd person when they have amnesia

Divisor Rich and Poor Numbers

Can an airline pilot be prosecuted for killing an unruly passenger who could not be physically restrained?

Why does string strummed with finger sound different from the one strummed with pick?

Gambler's Fallacy Dice

Is it a good idea to teach algorithm courses using pseudocode?

French equivalent of the German expression "flöten gehen"

How can sister protect herself from impulse purchases with a credit card?

Why are stats in Angband written as 18/** instead of 19, 20...?

Should I twist DC power and ground wires from a power supply?

Have GoT's showrunners reacted to the poor reception of the final season?

What should I wear to go and sign an employment contract?

How to customize the pie chart background in PowerPoint?

Shortest amud or daf in Shas?

pwaS eht tirsf dna tasl setterl fo hace dorw

Hotel booking: Why is Agoda much cheaper than booking.com?

What technology would Dwarves need to forge titanium?

Why is the S-duct intake on the Tu-154 uniquely oblong?

In Dutch history two people are referred to as "William III"; are there any more cases where this happens?

How do I balance a campaign consisting of four kobold PCs?

Why use a retrograde orbit?



vb.net Line numbering in multi line Rich Text Box if line starts with specific condition


VB.NET Syntax Highlighting in a Rich Text BoxHover tooltip on specific words in rich text box?convert csv data to DataTable in VB.netHow to op-en file and view in a rich text box using vb.net?VB.NET - Auto fill Rich Text Box in WebBrowser?Count Specific lines in a text file (that start with a number)Rich Text Box VB.NET Line By Line Stop and auto?VB.Net Form Controls For Formatting A Rich Text BoxOpening File Rich Text Box (VB.NET)VB.NET progressbar based on cmd output






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















Let me start by saying that I'm new to any language of coding besides G-code, and I've researched this until my fingers hurt. I've actually been working on this project for a little over a year now on my own, and this is the first hurdle I haven't been able to find my way around.



I'm creating an editor for cnc G-code, and i'm trying to add a Re-number function to it. I'm using a multi line richtextbox to display the the G-code to the user. I'm trying to edit each line of code that starts with the character "N", and if a line doesn't start with that character then it's left alone.



I figured the best way to do this would be to loop thru the RTB and pass each line into an array. Then I could use an If statement to see if a cell in the array started with the char "N" or in my case "blockLetter". Then use the replace function to correct the line Number.



This is what I have so far.



Dim increment As Integer = txtLNIncrement.Text
Dim blockLetter As String = txtLNStartTxt.Text
Dim count As Integer = 0
Dim block As Integer = count + increment

For Each cell As String In frmNC.NcTextBox.Lines
If cell.StartsWith(blockLetter) Then
Dim newCell As String = cell.Replace(blockLetter, block)
block = block + increment
MessageBox.Show(newCell)
End If
Next


Example of G-code that needs to be renumbered:
N50 M01
N60 T0101 (TOOL NAME)
N70 M41
N80 G96 S350
N90 M03
N100 M08



This is what I want:
N10 M01
N20 T0101 (TOOL NAME)
N30 M41
N40 G96 S350
N50 M03
N60 M08



This is what I'm getting when I run the code above:
1050 M01
2060 T0101 (TOOL NAME)
3070 M41
4080 G96 S350
5090 M03
60100 M08



I believe my issue is that the cell.replace is splitting each cell at the "N" character, and dropping it all together. Thus adding what I want to see in front of the existing numbers, minus the "N" character. How can I overwrite the existing block number to the correct ascending block number, and retain the "N" character? Am I going about this in the correct way, or is there a better way? Any help is greatly appreciated.










share|improve this question
























  • String.Replace is not exactly what you need: it replaces all occurrences of the pattern. You'ld change something you don't want to. You could IndexOf() on the first space (or Split()), then SubString() (take the first char), renumber, recombine and save the Lines in an array. Then, assign the array to the Lines Property (you cannot set a single line value).

    – Jimi
    Mar 23 at 18:22











  • I think I understand what your saying. Let me give that a try.

    – Cpt0bv10usly
    Mar 23 at 18:42











  • Try splitting each line into words and store in an array, take the first word from the array and replace it with the new value, then set the Richtextbox lines property to that array.

    – preciousbetine
    Mar 23 at 20:42











  • Are there actually four spaces before the "N"?

    – Idle_Mind
    Mar 23 at 20:57












  • no that was my mistake when I posted the question.

    – Cpt0bv10usly
    Mar 23 at 21:32

















1















Let me start by saying that I'm new to any language of coding besides G-code, and I've researched this until my fingers hurt. I've actually been working on this project for a little over a year now on my own, and this is the first hurdle I haven't been able to find my way around.



I'm creating an editor for cnc G-code, and i'm trying to add a Re-number function to it. I'm using a multi line richtextbox to display the the G-code to the user. I'm trying to edit each line of code that starts with the character "N", and if a line doesn't start with that character then it's left alone.



I figured the best way to do this would be to loop thru the RTB and pass each line into an array. Then I could use an If statement to see if a cell in the array started with the char "N" or in my case "blockLetter". Then use the replace function to correct the line Number.



This is what I have so far.



Dim increment As Integer = txtLNIncrement.Text
Dim blockLetter As String = txtLNStartTxt.Text
Dim count As Integer = 0
Dim block As Integer = count + increment

For Each cell As String In frmNC.NcTextBox.Lines
If cell.StartsWith(blockLetter) Then
Dim newCell As String = cell.Replace(blockLetter, block)
block = block + increment
MessageBox.Show(newCell)
End If
Next


Example of G-code that needs to be renumbered:
N50 M01
N60 T0101 (TOOL NAME)
N70 M41
N80 G96 S350
N90 M03
N100 M08



This is what I want:
N10 M01
N20 T0101 (TOOL NAME)
N30 M41
N40 G96 S350
N50 M03
N60 M08



This is what I'm getting when I run the code above:
1050 M01
2060 T0101 (TOOL NAME)
3070 M41
4080 G96 S350
5090 M03
60100 M08



I believe my issue is that the cell.replace is splitting each cell at the "N" character, and dropping it all together. Thus adding what I want to see in front of the existing numbers, minus the "N" character. How can I overwrite the existing block number to the correct ascending block number, and retain the "N" character? Am I going about this in the correct way, or is there a better way? Any help is greatly appreciated.










share|improve this question
























  • String.Replace is not exactly what you need: it replaces all occurrences of the pattern. You'ld change something you don't want to. You could IndexOf() on the first space (or Split()), then SubString() (take the first char), renumber, recombine and save the Lines in an array. Then, assign the array to the Lines Property (you cannot set a single line value).

    – Jimi
    Mar 23 at 18:22











  • I think I understand what your saying. Let me give that a try.

    – Cpt0bv10usly
    Mar 23 at 18:42











  • Try splitting each line into words and store in an array, take the first word from the array and replace it with the new value, then set the Richtextbox lines property to that array.

    – preciousbetine
    Mar 23 at 20:42











  • Are there actually four spaces before the "N"?

    – Idle_Mind
    Mar 23 at 20:57












  • no that was my mistake when I posted the question.

    – Cpt0bv10usly
    Mar 23 at 21:32













1












1








1








Let me start by saying that I'm new to any language of coding besides G-code, and I've researched this until my fingers hurt. I've actually been working on this project for a little over a year now on my own, and this is the first hurdle I haven't been able to find my way around.



I'm creating an editor for cnc G-code, and i'm trying to add a Re-number function to it. I'm using a multi line richtextbox to display the the G-code to the user. I'm trying to edit each line of code that starts with the character "N", and if a line doesn't start with that character then it's left alone.



I figured the best way to do this would be to loop thru the RTB and pass each line into an array. Then I could use an If statement to see if a cell in the array started with the char "N" or in my case "blockLetter". Then use the replace function to correct the line Number.



This is what I have so far.



Dim increment As Integer = txtLNIncrement.Text
Dim blockLetter As String = txtLNStartTxt.Text
Dim count As Integer = 0
Dim block As Integer = count + increment

For Each cell As String In frmNC.NcTextBox.Lines
If cell.StartsWith(blockLetter) Then
Dim newCell As String = cell.Replace(blockLetter, block)
block = block + increment
MessageBox.Show(newCell)
End If
Next


Example of G-code that needs to be renumbered:
N50 M01
N60 T0101 (TOOL NAME)
N70 M41
N80 G96 S350
N90 M03
N100 M08



This is what I want:
N10 M01
N20 T0101 (TOOL NAME)
N30 M41
N40 G96 S350
N50 M03
N60 M08



This is what I'm getting when I run the code above:
1050 M01
2060 T0101 (TOOL NAME)
3070 M41
4080 G96 S350
5090 M03
60100 M08



I believe my issue is that the cell.replace is splitting each cell at the "N" character, and dropping it all together. Thus adding what I want to see in front of the existing numbers, minus the "N" character. How can I overwrite the existing block number to the correct ascending block number, and retain the "N" character? Am I going about this in the correct way, or is there a better way? Any help is greatly appreciated.










share|improve this question
















Let me start by saying that I'm new to any language of coding besides G-code, and I've researched this until my fingers hurt. I've actually been working on this project for a little over a year now on my own, and this is the first hurdle I haven't been able to find my way around.



I'm creating an editor for cnc G-code, and i'm trying to add a Re-number function to it. I'm using a multi line richtextbox to display the the G-code to the user. I'm trying to edit each line of code that starts with the character "N", and if a line doesn't start with that character then it's left alone.



I figured the best way to do this would be to loop thru the RTB and pass each line into an array. Then I could use an If statement to see if a cell in the array started with the char "N" or in my case "blockLetter". Then use the replace function to correct the line Number.



This is what I have so far.



Dim increment As Integer = txtLNIncrement.Text
Dim blockLetter As String = txtLNStartTxt.Text
Dim count As Integer = 0
Dim block As Integer = count + increment

For Each cell As String In frmNC.NcTextBox.Lines
If cell.StartsWith(blockLetter) Then
Dim newCell As String = cell.Replace(blockLetter, block)
block = block + increment
MessageBox.Show(newCell)
End If
Next


Example of G-code that needs to be renumbered:
N50 M01
N60 T0101 (TOOL NAME)
N70 M41
N80 G96 S350
N90 M03
N100 M08



This is what I want:
N10 M01
N20 T0101 (TOOL NAME)
N30 M41
N40 G96 S350
N50 M03
N60 M08



This is what I'm getting when I run the code above:
1050 M01
2060 T0101 (TOOL NAME)
3070 M41
4080 G96 S350
5090 M03
60100 M08



I believe my issue is that the cell.replace is splitting each cell at the "N" character, and dropping it all together. Thus adding what I want to see in front of the existing numbers, minus the "N" character. How can I overwrite the existing block number to the correct ascending block number, and retain the "N" character? Am I going about this in the correct way, or is there a better way? Any help is greatly appreciated.







vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 21:33







Cpt0bv10usly

















asked Mar 23 at 17:29









Cpt0bv10uslyCpt0bv10usly

84




84












  • String.Replace is not exactly what you need: it replaces all occurrences of the pattern. You'ld change something you don't want to. You could IndexOf() on the first space (or Split()), then SubString() (take the first char), renumber, recombine and save the Lines in an array. Then, assign the array to the Lines Property (you cannot set a single line value).

    – Jimi
    Mar 23 at 18:22











  • I think I understand what your saying. Let me give that a try.

    – Cpt0bv10usly
    Mar 23 at 18:42











  • Try splitting each line into words and store in an array, take the first word from the array and replace it with the new value, then set the Richtextbox lines property to that array.

    – preciousbetine
    Mar 23 at 20:42











  • Are there actually four spaces before the "N"?

    – Idle_Mind
    Mar 23 at 20:57












  • no that was my mistake when I posted the question.

    – Cpt0bv10usly
    Mar 23 at 21:32

















  • String.Replace is not exactly what you need: it replaces all occurrences of the pattern. You'ld change something you don't want to. You could IndexOf() on the first space (or Split()), then SubString() (take the first char), renumber, recombine and save the Lines in an array. Then, assign the array to the Lines Property (you cannot set a single line value).

    – Jimi
    Mar 23 at 18:22











  • I think I understand what your saying. Let me give that a try.

    – Cpt0bv10usly
    Mar 23 at 18:42











  • Try splitting each line into words and store in an array, take the first word from the array and replace it with the new value, then set the Richtextbox lines property to that array.

    – preciousbetine
    Mar 23 at 20:42











  • Are there actually four spaces before the "N"?

    – Idle_Mind
    Mar 23 at 20:57












  • no that was my mistake when I posted the question.

    – Cpt0bv10usly
    Mar 23 at 21:32
















String.Replace is not exactly what you need: it replaces all occurrences of the pattern. You'ld change something you don't want to. You could IndexOf() on the first space (or Split()), then SubString() (take the first char), renumber, recombine and save the Lines in an array. Then, assign the array to the Lines Property (you cannot set a single line value).

– Jimi
Mar 23 at 18:22





String.Replace is not exactly what you need: it replaces all occurrences of the pattern. You'ld change something you don't want to. You could IndexOf() on the first space (or Split()), then SubString() (take the first char), renumber, recombine and save the Lines in an array. Then, assign the array to the Lines Property (you cannot set a single line value).

– Jimi
Mar 23 at 18:22













I think I understand what your saying. Let me give that a try.

– Cpt0bv10usly
Mar 23 at 18:42





I think I understand what your saying. Let me give that a try.

– Cpt0bv10usly
Mar 23 at 18:42













Try splitting each line into words and store in an array, take the first word from the array and replace it with the new value, then set the Richtextbox lines property to that array.

– preciousbetine
Mar 23 at 20:42





Try splitting each line into words and store in an array, take the first word from the array and replace it with the new value, then set the Richtextbox lines property to that array.

– preciousbetine
Mar 23 at 20:42













Are there actually four spaces before the "N"?

– Idle_Mind
Mar 23 at 20:57






Are there actually four spaces before the "N"?

– Idle_Mind
Mar 23 at 20:57














no that was my mistake when I posted the question.

– Cpt0bv10usly
Mar 23 at 21:32





no that was my mistake when I posted the question.

– Cpt0bv10usly
Mar 23 at 21:32












2 Answers
2






active

oldest

votes


















1














Try something like this out:



Private increment As Integer = 10
Private blockLetter As String = "N"

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newLine As String
Dim values() As String
Dim lineNumber As Integer = 0
Dim lines As New List(Of String)(NcTextBox.Lines)
For i As Integer = 0 To lines.Count - 1
If lines(i).TrimStart().StartsWith(blockLetter) Then
values = lines(i).TrimStart(" " & blockLetter.ToCharArray).Split(" ")
lineNumber = lineNumber + increment
values(0) = lineNumber
newLine = blockLetter & String.Join(" ", values)
lines(i) = newLine
End If
Next
NcTextBox.Lines = lines.ToArray
End Sub





share|improve this answer

























  • Resolved. That is amazing. I have a question about it if you don't mind. I understand how it works, except for the " " at the begging and ending of the .split. I get the last one is splitting the string at the first blank space, but what is the first " " for?

    – Cpt0bv10usly
    Mar 23 at 21:56












  • The one at the beginning, which is actually part of the Trim() call, gets rid of leading spaces and the "N". The one at the end says to split the string on spaces.

    – Idle_Mind
    Mar 23 at 22:26











  • Well, I can't thank you enough.

    – Cpt0bv10usly
    Mar 23 at 22:50











  • @Cpt0bv10usly Please accept the answer by clicking the check mark (tick mark) to the left of the answer. This aids subsequent viewers to quickly get to a solution.

    – Mary
    Mar 24 at 0:44


















0














it's very simple:



Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim blockLetter As String = "N"
Dim increment As Integer = 1
For i As Integer = 0 To RichTextBox1.Lines.Length - 1 Step 1
Dim fullLine As String = RichTextBox1.Lines(i)

If fullLine.StartsWith(blockLetter) Then
Dim numbering As String = fullLine.Remove(RichTextBox1.Lines(i).IndexOf(" "))
Dim block As Integer = numbering.Substring(1)
Dim newCell As String = blockLetter & block + increment
MessageBox.Show(newCell)
End If
Next

End Sub


Result:




The Label1.Text will increase with button click.




It's all about Substring() starting from index 1 after 'N', so you will get the number.



Good luck with your coding!






share|improve this answer




















  • 1





    cell.Substring(1) is a string, you cannot assign it to an Integer variable: if the line is N60 T0101 (TOOL NAME), then SubString(1) will be 60 T0101 (TOOL NAME). Also, you cannot sum an Integer and a String.

    – Jimi
    Mar 23 at 18:34











  • Thanks Jimi for your point, I edited my answer. Also, I didn't sum String and Integer, because block will definitely return a number even if it comes from Substring(). You can try it :)

    – kh3e
    Mar 23 at 23:01











  • @kh3e Please turn on Option Strict. This is a 2 part process. First for the current project - In Solution Explorer double click My Project. Choose Compile on the left. In the Option Strict drop-down select ON. Second for future projects - Go to the Tools Menu -> Options -> Projects and Solutions -> VB Defaults. In the Option Strict drop-down select ON. This will save you from bugs at runtime.

    – Mary
    Mar 24 at 0:38











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316483%2fvb-net-line-numbering-in-multi-line-rich-text-box-if-line-starts-with-specific-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try something like this out:



Private increment As Integer = 10
Private blockLetter As String = "N"

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newLine As String
Dim values() As String
Dim lineNumber As Integer = 0
Dim lines As New List(Of String)(NcTextBox.Lines)
For i As Integer = 0 To lines.Count - 1
If lines(i).TrimStart().StartsWith(blockLetter) Then
values = lines(i).TrimStart(" " & blockLetter.ToCharArray).Split(" ")
lineNumber = lineNumber + increment
values(0) = lineNumber
newLine = blockLetter & String.Join(" ", values)
lines(i) = newLine
End If
Next
NcTextBox.Lines = lines.ToArray
End Sub





share|improve this answer

























  • Resolved. That is amazing. I have a question about it if you don't mind. I understand how it works, except for the " " at the begging and ending of the .split. I get the last one is splitting the string at the first blank space, but what is the first " " for?

    – Cpt0bv10usly
    Mar 23 at 21:56












  • The one at the beginning, which is actually part of the Trim() call, gets rid of leading spaces and the "N". The one at the end says to split the string on spaces.

    – Idle_Mind
    Mar 23 at 22:26











  • Well, I can't thank you enough.

    – Cpt0bv10usly
    Mar 23 at 22:50











  • @Cpt0bv10usly Please accept the answer by clicking the check mark (tick mark) to the left of the answer. This aids subsequent viewers to quickly get to a solution.

    – Mary
    Mar 24 at 0:44















1














Try something like this out:



Private increment As Integer = 10
Private blockLetter As String = "N"

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newLine As String
Dim values() As String
Dim lineNumber As Integer = 0
Dim lines As New List(Of String)(NcTextBox.Lines)
For i As Integer = 0 To lines.Count - 1
If lines(i).TrimStart().StartsWith(blockLetter) Then
values = lines(i).TrimStart(" " & blockLetter.ToCharArray).Split(" ")
lineNumber = lineNumber + increment
values(0) = lineNumber
newLine = blockLetter & String.Join(" ", values)
lines(i) = newLine
End If
Next
NcTextBox.Lines = lines.ToArray
End Sub





share|improve this answer

























  • Resolved. That is amazing. I have a question about it if you don't mind. I understand how it works, except for the " " at the begging and ending of the .split. I get the last one is splitting the string at the first blank space, but what is the first " " for?

    – Cpt0bv10usly
    Mar 23 at 21:56












  • The one at the beginning, which is actually part of the Trim() call, gets rid of leading spaces and the "N". The one at the end says to split the string on spaces.

    – Idle_Mind
    Mar 23 at 22:26











  • Well, I can't thank you enough.

    – Cpt0bv10usly
    Mar 23 at 22:50











  • @Cpt0bv10usly Please accept the answer by clicking the check mark (tick mark) to the left of the answer. This aids subsequent viewers to quickly get to a solution.

    – Mary
    Mar 24 at 0:44













1












1








1







Try something like this out:



Private increment As Integer = 10
Private blockLetter As String = "N"

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newLine As String
Dim values() As String
Dim lineNumber As Integer = 0
Dim lines As New List(Of String)(NcTextBox.Lines)
For i As Integer = 0 To lines.Count - 1
If lines(i).TrimStart().StartsWith(blockLetter) Then
values = lines(i).TrimStart(" " & blockLetter.ToCharArray).Split(" ")
lineNumber = lineNumber + increment
values(0) = lineNumber
newLine = blockLetter & String.Join(" ", values)
lines(i) = newLine
End If
Next
NcTextBox.Lines = lines.ToArray
End Sub





share|improve this answer















Try something like this out:



Private increment As Integer = 10
Private blockLetter As String = "N"

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim newLine As String
Dim values() As String
Dim lineNumber As Integer = 0
Dim lines As New List(Of String)(NcTextBox.Lines)
For i As Integer = 0 To lines.Count - 1
If lines(i).TrimStart().StartsWith(blockLetter) Then
values = lines(i).TrimStart(" " & blockLetter.ToCharArray).Split(" ")
lineNumber = lineNumber + increment
values(0) = lineNumber
newLine = blockLetter & String.Join(" ", values)
lines(i) = newLine
End If
Next
NcTextBox.Lines = lines.ToArray
End Sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 23 at 21:55

























answered Mar 23 at 21:06









Idle_MindIdle_Mind

24.6k21624




24.6k21624












  • Resolved. That is amazing. I have a question about it if you don't mind. I understand how it works, except for the " " at the begging and ending of the .split. I get the last one is splitting the string at the first blank space, but what is the first " " for?

    – Cpt0bv10usly
    Mar 23 at 21:56












  • The one at the beginning, which is actually part of the Trim() call, gets rid of leading spaces and the "N". The one at the end says to split the string on spaces.

    – Idle_Mind
    Mar 23 at 22:26











  • Well, I can't thank you enough.

    – Cpt0bv10usly
    Mar 23 at 22:50











  • @Cpt0bv10usly Please accept the answer by clicking the check mark (tick mark) to the left of the answer. This aids subsequent viewers to quickly get to a solution.

    – Mary
    Mar 24 at 0:44

















  • Resolved. That is amazing. I have a question about it if you don't mind. I understand how it works, except for the " " at the begging and ending of the .split. I get the last one is splitting the string at the first blank space, but what is the first " " for?

    – Cpt0bv10usly
    Mar 23 at 21:56












  • The one at the beginning, which is actually part of the Trim() call, gets rid of leading spaces and the "N". The one at the end says to split the string on spaces.

    – Idle_Mind
    Mar 23 at 22:26











  • Well, I can't thank you enough.

    – Cpt0bv10usly
    Mar 23 at 22:50











  • @Cpt0bv10usly Please accept the answer by clicking the check mark (tick mark) to the left of the answer. This aids subsequent viewers to quickly get to a solution.

    – Mary
    Mar 24 at 0:44
















Resolved. That is amazing. I have a question about it if you don't mind. I understand how it works, except for the " " at the begging and ending of the .split. I get the last one is splitting the string at the first blank space, but what is the first " " for?

– Cpt0bv10usly
Mar 23 at 21:56






Resolved. That is amazing. I have a question about it if you don't mind. I understand how it works, except for the " " at the begging and ending of the .split. I get the last one is splitting the string at the first blank space, but what is the first " " for?

– Cpt0bv10usly
Mar 23 at 21:56














The one at the beginning, which is actually part of the Trim() call, gets rid of leading spaces and the "N". The one at the end says to split the string on spaces.

– Idle_Mind
Mar 23 at 22:26





The one at the beginning, which is actually part of the Trim() call, gets rid of leading spaces and the "N". The one at the end says to split the string on spaces.

– Idle_Mind
Mar 23 at 22:26













Well, I can't thank you enough.

– Cpt0bv10usly
Mar 23 at 22:50





Well, I can't thank you enough.

– Cpt0bv10usly
Mar 23 at 22:50













@Cpt0bv10usly Please accept the answer by clicking the check mark (tick mark) to the left of the answer. This aids subsequent viewers to quickly get to a solution.

– Mary
Mar 24 at 0:44





@Cpt0bv10usly Please accept the answer by clicking the check mark (tick mark) to the left of the answer. This aids subsequent viewers to quickly get to a solution.

– Mary
Mar 24 at 0:44













0














it's very simple:



Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim blockLetter As String = "N"
Dim increment As Integer = 1
For i As Integer = 0 To RichTextBox1.Lines.Length - 1 Step 1
Dim fullLine As String = RichTextBox1.Lines(i)

If fullLine.StartsWith(blockLetter) Then
Dim numbering As String = fullLine.Remove(RichTextBox1.Lines(i).IndexOf(" "))
Dim block As Integer = numbering.Substring(1)
Dim newCell As String = blockLetter & block + increment
MessageBox.Show(newCell)
End If
Next

End Sub


Result:




The Label1.Text will increase with button click.




It's all about Substring() starting from index 1 after 'N', so you will get the number.



Good luck with your coding!






share|improve this answer




















  • 1





    cell.Substring(1) is a string, you cannot assign it to an Integer variable: if the line is N60 T0101 (TOOL NAME), then SubString(1) will be 60 T0101 (TOOL NAME). Also, you cannot sum an Integer and a String.

    – Jimi
    Mar 23 at 18:34











  • Thanks Jimi for your point, I edited my answer. Also, I didn't sum String and Integer, because block will definitely return a number even if it comes from Substring(). You can try it :)

    – kh3e
    Mar 23 at 23:01











  • @kh3e Please turn on Option Strict. This is a 2 part process. First for the current project - In Solution Explorer double click My Project. Choose Compile on the left. In the Option Strict drop-down select ON. Second for future projects - Go to the Tools Menu -> Options -> Projects and Solutions -> VB Defaults. In the Option Strict drop-down select ON. This will save you from bugs at runtime.

    – Mary
    Mar 24 at 0:38















0














it's very simple:



Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim blockLetter As String = "N"
Dim increment As Integer = 1
For i As Integer = 0 To RichTextBox1.Lines.Length - 1 Step 1
Dim fullLine As String = RichTextBox1.Lines(i)

If fullLine.StartsWith(blockLetter) Then
Dim numbering As String = fullLine.Remove(RichTextBox1.Lines(i).IndexOf(" "))
Dim block As Integer = numbering.Substring(1)
Dim newCell As String = blockLetter & block + increment
MessageBox.Show(newCell)
End If
Next

End Sub


Result:




The Label1.Text will increase with button click.




It's all about Substring() starting from index 1 after 'N', so you will get the number.



Good luck with your coding!






share|improve this answer




















  • 1





    cell.Substring(1) is a string, you cannot assign it to an Integer variable: if the line is N60 T0101 (TOOL NAME), then SubString(1) will be 60 T0101 (TOOL NAME). Also, you cannot sum an Integer and a String.

    – Jimi
    Mar 23 at 18:34











  • Thanks Jimi for your point, I edited my answer. Also, I didn't sum String and Integer, because block will definitely return a number even if it comes from Substring(). You can try it :)

    – kh3e
    Mar 23 at 23:01











  • @kh3e Please turn on Option Strict. This is a 2 part process. First for the current project - In Solution Explorer double click My Project. Choose Compile on the left. In the Option Strict drop-down select ON. Second for future projects - Go to the Tools Menu -> Options -> Projects and Solutions -> VB Defaults. In the Option Strict drop-down select ON. This will save you from bugs at runtime.

    – Mary
    Mar 24 at 0:38













0












0








0







it's very simple:



Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim blockLetter As String = "N"
Dim increment As Integer = 1
For i As Integer = 0 To RichTextBox1.Lines.Length - 1 Step 1
Dim fullLine As String = RichTextBox1.Lines(i)

If fullLine.StartsWith(blockLetter) Then
Dim numbering As String = fullLine.Remove(RichTextBox1.Lines(i).IndexOf(" "))
Dim block As Integer = numbering.Substring(1)
Dim newCell As String = blockLetter & block + increment
MessageBox.Show(newCell)
End If
Next

End Sub


Result:




The Label1.Text will increase with button click.




It's all about Substring() starting from index 1 after 'N', so you will get the number.



Good luck with your coding!






share|improve this answer















it's very simple:



Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim blockLetter As String = "N"
Dim increment As Integer = 1
For i As Integer = 0 To RichTextBox1.Lines.Length - 1 Step 1
Dim fullLine As String = RichTextBox1.Lines(i)

If fullLine.StartsWith(blockLetter) Then
Dim numbering As String = fullLine.Remove(RichTextBox1.Lines(i).IndexOf(" "))
Dim block As Integer = numbering.Substring(1)
Dim newCell As String = blockLetter & block + increment
MessageBox.Show(newCell)
End If
Next

End Sub


Result:




The Label1.Text will increase with button click.




It's all about Substring() starting from index 1 after 'N', so you will get the number.



Good luck with your coding!







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 23 at 22:47

























answered Mar 23 at 17:50









kh3ekh3e

140110




140110







  • 1





    cell.Substring(1) is a string, you cannot assign it to an Integer variable: if the line is N60 T0101 (TOOL NAME), then SubString(1) will be 60 T0101 (TOOL NAME). Also, you cannot sum an Integer and a String.

    – Jimi
    Mar 23 at 18:34











  • Thanks Jimi for your point, I edited my answer. Also, I didn't sum String and Integer, because block will definitely return a number even if it comes from Substring(). You can try it :)

    – kh3e
    Mar 23 at 23:01











  • @kh3e Please turn on Option Strict. This is a 2 part process. First for the current project - In Solution Explorer double click My Project. Choose Compile on the left. In the Option Strict drop-down select ON. Second for future projects - Go to the Tools Menu -> Options -> Projects and Solutions -> VB Defaults. In the Option Strict drop-down select ON. This will save you from bugs at runtime.

    – Mary
    Mar 24 at 0:38












  • 1





    cell.Substring(1) is a string, you cannot assign it to an Integer variable: if the line is N60 T0101 (TOOL NAME), then SubString(1) will be 60 T0101 (TOOL NAME). Also, you cannot sum an Integer and a String.

    – Jimi
    Mar 23 at 18:34











  • Thanks Jimi for your point, I edited my answer. Also, I didn't sum String and Integer, because block will definitely return a number even if it comes from Substring(). You can try it :)

    – kh3e
    Mar 23 at 23:01











  • @kh3e Please turn on Option Strict. This is a 2 part process. First for the current project - In Solution Explorer double click My Project. Choose Compile on the left. In the Option Strict drop-down select ON. Second for future projects - Go to the Tools Menu -> Options -> Projects and Solutions -> VB Defaults. In the Option Strict drop-down select ON. This will save you from bugs at runtime.

    – Mary
    Mar 24 at 0:38







1




1





cell.Substring(1) is a string, you cannot assign it to an Integer variable: if the line is N60 T0101 (TOOL NAME), then SubString(1) will be 60 T0101 (TOOL NAME). Also, you cannot sum an Integer and a String.

– Jimi
Mar 23 at 18:34





cell.Substring(1) is a string, you cannot assign it to an Integer variable: if the line is N60 T0101 (TOOL NAME), then SubString(1) will be 60 T0101 (TOOL NAME). Also, you cannot sum an Integer and a String.

– Jimi
Mar 23 at 18:34













Thanks Jimi for your point, I edited my answer. Also, I didn't sum String and Integer, because block will definitely return a number even if it comes from Substring(). You can try it :)

– kh3e
Mar 23 at 23:01





Thanks Jimi for your point, I edited my answer. Also, I didn't sum String and Integer, because block will definitely return a number even if it comes from Substring(). You can try it :)

– kh3e
Mar 23 at 23:01













@kh3e Please turn on Option Strict. This is a 2 part process. First for the current project - In Solution Explorer double click My Project. Choose Compile on the left. In the Option Strict drop-down select ON. Second for future projects - Go to the Tools Menu -> Options -> Projects and Solutions -> VB Defaults. In the Option Strict drop-down select ON. This will save you from bugs at runtime.

– Mary
Mar 24 at 0:38





@kh3e Please turn on Option Strict. This is a 2 part process. First for the current project - In Solution Explorer double click My Project. Choose Compile on the left. In the Option Strict drop-down select ON. Second for future projects - Go to the Tools Menu -> Options -> Projects and Solutions -> VB Defaults. In the Option Strict drop-down select ON. This will save you from bugs at runtime.

– Mary
Mar 24 at 0:38

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316483%2fvb-net-line-numbering-in-multi-line-rich-text-box-if-line-starts-with-specific-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현