How do I remove the box symbol that shows up for a line break when I output a string to a cell? - vba

I have a userform where the user enters a description of their project into a textbox and it is stored in a string. When the user runs the "Generate Report" routine that string is output to a single cell. If the user entered line breaks, they are present in the output, but there is also a "box" character for each line break. I can manually delete the "box" character and the line break is still there in the cell, but how do I prevent the "box" character from showing up in the first place?

Your string is probably carrying a vbCrLf (Carriage Return + Line Feed). All you need to do is remove the CR of the CR+LF.
Try this:
(YourCell.Value Here) = Replace(YourString, vbCrLf, vbLf)
Good luck.

Related

How to get number of specific line in multi line text box after loop check in vb .net?

I have a multi-line text box that contains a number of blank lines and I want to check these blank lines by loop and then give me the number of that blank line.
For Each line As String In TextBox2.Lines
If line = "" Then
'line.linenumber
End If
Next

How to prevent line feeds (vbLf) and carriage returns (vbCr) in text boxes in a vb.net text file?

How to prevent line feeds (vbLf) and carriage returns (vbCr) in a text box that should only be one line, in a text file? It can happen that these carriage return characters and these new line characters are present (for example during a copy and paste) in the body of the text and thus make the reading of the file impossible. This has happened to me before, and I think I need to set up a check for the presence of these characters and thus warn the user to check his line before any recording. Thank you in advance. Claude.
Replace the CR and LF with nothing?
textBoxWithCrLf.Text.Replace(vbCr, "").Replace(vbLf, "")
Note, this doesn't modify the contents of the textbox, it generates a new string with no CRLF, so you'd use it like:
somefilewriter.SomeWriteStringMethod( textBoxWithCrLf.Text.Replace(vbCr, "").Replace(vbLf, "") )

VB.NET - Appending text to the last line of text file leaves (sometimes) an empty line

The intention of the software I am coding is to append a string to the last line of a text file. The problem I am experiencing is that depending on the situation, sometimes I get an empty line when I try to append text to the last line of a text file.
My text file is very simple. It contains a few lines of text and each line contains a few words. When I open the text file with Windows' Notepad (without editing the content of the text file) and I move the caret to the end of the entire file, sometimes the caret is positioned at the end of the last line with content (text), and sometimes it is positioned at an empty line that doesn't contain even a white space.
When the caret's ending position corresponds to the last char of a line that contains text, I don't experience any problem appending some text programmatically. The programmatically appended line is at a new line and there isn't any empty line between the old last line and the current last line in the text file.
The problem appears when I can move the caret in the text file to the last possible position and that position corresponds to an empty line. In that case, when I try to append a new line programmatically, I can see an empty line before the just added line.
I have tried different codes and techniques, but it always happens the same to me.
The code I am actually using is:
If stringLastLine.Length = 0 Then
Using sw As StreamWriter = New System.IO.StreamWriter(filePath, True)
sw.Write("Inserted text")
sw.Close()
End Using
ElseIf stringLastLine.Length > 0 Then
Using sw As StreamWriter = New System.IO.StreamWriter(filePath, True)
sw.Write(Environment.NewLine & "Inserted text")
sw.Close()
End Using
End If
Basically, I am trying to detect if the last line length is over zero, so it's a line with text content and I will use "environment.newline + string". If it's a line without content (length = 0) I add directly the string without using "environment.newline". In the case that length = 0 I always get an empty line in between.
Any idea to solve this problem?
How about trimming your text to ensure there's no end of line characters at the end (the whole text)? Right now you might have an issue with multiple blank lines:
text = text.TrimEnd({Convert.ToChar(10), Convert.ToChar(13)})
This handles the EOL characters.

Textbox not using vbCrLf unless converted to vbNewLine

I have a StoredProcedure that returns a string.
In the string I put CHAR(13) and CHAR(10) to have carriage return and line feed.
I read the string from a winform in VB.NET and the string correctly has a "VBCrLf" in it. When I look at the string during debug (you know, using the little magnifing glass) the lines are correctly there.
THEN: I put the string in the text of a Multiline Textbox and the lines disappear, everything is on a single line.
If I then apply:
myString.Replace(vbCrLf, vbNewLine)
and put it back in the same textBox, everything works fine again.
How can avoid the replace?
Thankx

How to paste text to end of every line? Sublime 2

I'm curious if there is a way to paste text to the end of every line in Sublime 2? And conversely, to the beginning of every line.
test line one
test line two
test line three
test line four
...
Say you have 100 lines of text in the editor, and you want to paste quotation marks to the beginning and end of each line.
Is there an easy way to do this or a plugin that anyone would know of? This would often save me a lot of time on various projects.
Thanks.
Yeah Regex is cool, but there are other alternative.
Select all the lines you want to prefix or suffix
Goto menu Selection -> Split into Lines (Cmd/Ctrl + Shift + L)
This allows you to edit multiple lines at once. Now you can add *Quotes (") or anything * at start and end of each lines.
Here's the workflow I use all the time, using the keyboard only
Ctrl/Cmd + A Select All
Ctrl/Cmd + Shift + L Split into Lines
' Surround every line with quotes
Note that this doesn't work if there are blank lines in the selection.
Select all the lines on which you want to add prefix or suffix. (But if you want to add prefix or suffix to only specific lines, you can use ctrl+Left mouse button to create multiple cursors.)
Push Ctrl+Shift+L.
Push Home key and add prefix.
Push End key and add suffix.
Note, disable wordwrap, otherwise it will not work properly if your lines are longer than sublime's width.
Let's say you have these lines of code:
test line one
test line two
test line three
test line four
Using Search and Replace Ctrl+H with Regex let's find this: ^ and replace it with ", we'll have this:
"test line one
"test line two
"test line three
"test line four
Now let's search this: $ and replace it with ", now we'll have this:
"test line one"
"test line two"
"test line three"
"test line four"
You can use the Search & Replace feature with this regex ^([\w\d\_\.\s\-]*)$ to find text and the replaced text is "$1".
Use column selection. Column selection is one of the unique features of Sublime2; it is used to give you multiple matched cursors (tutorial here). To get multiple cursors, do one of the following:
Mouse:
Hold down the shift (Windows/Linux) or option key (Mac) while selecting a region with the mouse.
Clicking middle mouse button (or scroll) will select as a column also.
Keyboard:
Select the desired region.
Type control+shift+L (Windows/Linux) or command+shift+L (Mac)
You now have multiple lines selected, so you could type a quotation mark at the beginning and end of each line. It would be better to take advantage of Sublime's capabilities, and just type ". When you do this, Sublime automatically quotes the selected text.
Type esc to exit multiple cursor mode.
Select all lines you want to add a suffix or prefix.(command+ A to select all the lines)
Press command+shift+L. This will put one cursor at the end of every line and all the selected lines would still be selected.
For adding suffix press command+right and for adding prefix command+left. This will deselect all the earlier selected text and there will only be cursors at the end or start of every line.
Add required text