How to check if label in VB.net (VS2008) has multiple lines? - vb.net

I have a method that saves form controls data to a text file, including its text. IF a label has multiple lines, this breaks the text file writing multiple lines to it.
I was instructed to simply ignore multiple-line labels and don't include it in the file, but I don't know how to check whether or not a label has can multiple lines or not so I can throw in an 'if' statement.
Thanks!

You can check for new lines in the label like this:
If Not lblText.Text.Contains(Environment.NewLine) Then
So if the label has a newline, ignore it.

Test for something like this
Label1.Text.Contains(Environment.NewLine)
Environment.NewLine Property

myLabel.Text.Contains(vbCrlf)
Sorry, VB.net isn't my first language.

Related

Word - Conditional Text

I'm having to convert some documents which had been built in OpenOffice over to word, and one thing which seems overly complicated in Word is conditional text. OO had some features which made this a breeze, but I'm thinking I'm missing something in Word.
For more simple pieces of text I've used the {IF {DOCVARIABLE xxxx} = ...} method which seems to work well with single lines of text.
For longer blocks of text I've tried using a similar method but inserting an Autotext block. This works well if the content is static, but if the content I'm inserting needs to be edited, updating the document ends up replacing any changes with the Autotext block. So this method won't work for parts of my document.
Most of the search results I'm seeing use some variation of the two methods above. Is there something else I can use which allows blocks of text, possibly including tables, to be conditionally inserted or hidden and also editable?
Macros are okay since this is how I'm setting various DOCVARIABLE parameters in the document.
I'm using Word 2016 on Windows 7.
After doing more experimenting, it looks like I can use bookmarks to do what I need.
I can select the block of text I want to conditionally show/hide, then create a bookmark for the selection.
Then in my macro I can hide the section when necessary with:
ActiveDocument.Bookmarks("MyBookmarkName").Range.Font.Hidden = True
or show it again using False instead of True. This seems to hide tables and other things within that block of text. I'd love it if the Word developers would add some of the features for this type of thing which are in OpenOffice.

PDFBOX - WordUtils.wrap - need to display bold and non-bolded text on same line

I am a newbie to pdfbox AND java - trying to replicate a pdf letter with logos formatting etc. I need to use mixed font (bold) within a sentence. Presently appending paragraph string, using WordUtils.wrap, then begin.Text , etc. to parse and display (drawString has strikethrough cannot select this - I did find info for multi font using it). As field values will vary in text and length, I cannot simply search on, split and change font to display. Unable to use tags to do this (OMG I've tried everything I can think of!), but hoping there is a way to use a single char identifier for beginning of bold and another for end of bold??? One issue is that no guarantee the identifiers would end up on the same line of the paragraph. UGH. Everything else is perfect, EXCEPT the text I need to bold. Does anyone have any suggestions?? I am required to use pdfbox to accomplish this - cannot use Itext. Help please! Thank you!!
SOLVED - I figured it out. Thank you for your suggestions!
I did not want to use positioning, needing to keep it as simple as possible. We'll eventually need to implement hundreds of letters. I Am using Utils.wrap strictly as a line parser, not formatting, so that is cool.
Using 2 identifiers - 3 checks -
1) both on the same line,
2) beginning bold on one line, and
3) end bold on another line.
Using split string by " " and checks equal to identifiers. Formatting is perfect. Going forward may need to modify, if for some crazy reason identifiers are contained in letter text.
It works for the 1st roll-out. Thanks again - your help is much appreciated!!!

MS Word, how to change formatting of entire paragraphs automatically in whole document?

I have a 20-page word document punctuated with descriptive notes throughout, like this:
3 Input Data Requirements
Some requirement text.
NOTE: This is a descriptive note about the requirement, which is the paragraph that I would like to use find-and-replace or a VBA script to select automatically and change the formatting to italicized. The notes invariably end in a carriage-return: ¶.
If it was just a text document, not MS-Word, I would just use a regex in a code editor like sublime to wrap it with <I>...</I> or something along those lines.
Preferably, is there a way to do this in Word's "advanced" find-and-replace feature? Or if not, what's the best way to do it in VBA?
I've tried using a search string like this in find-and-replace: NOTE: *[a-z0-9,. A-Z)(-]{1,255}^l but the line-break part doesn't seem to work, and the 255 char max isn't enough for many of the paragraphs.
EDIT: Another slightly important detail: The doc is automatically generated from another piece of software as a .RTF, which I promptly converted to .docx.
Attempt #2: Use Notepad++ to find and replace using regex. Remove quotes.
Find: "( NOTE: .*?)\r"
Replace with: " \i \1 \i0 \r "
//OLD
Sure is. No VBA or fancy tricks needed.
CTRL + H to bring up the replace dialog.
Click "More".
Select "Font" in the drop down menu called "Format".
Click italics.
Enter find and replace text as the same thing. Make sure you set this up right so that you don't accidentally replace substrings (e.g. goal to replace all " test " with " nice ", testing -> niceing).
Should work. If you need to alter entire paragraphs, consistently, then you probably should have used the styles on those paragraphs to begin with. That way, you can change all of them at once by updating the style itself.
You can use Advance Find, yes. Find Next and then Replace makes the selection Italic.

How do you get a Textbox to Read line by line by label.text

Okay so I fell into a loop and got stumped. I have been trying many ways to try and get a VB.net (Label.text) to = each independent line entered. Is there an easier alternative that will not come up with warnings? Just Curious. I could use a Listbox to Manage the Items and use those lines instead of a Textbox in Multi-lined, Just wondering how to get multi line function that reads text from a textbox to a label.text if many lines are entered.
For Example.
If ProgressBar1.Value = 0% Then Label10.Text = (TextBox1.Text + vbNewLine)
Problem with this is that it Addes it all into the Label. Id like a way to have line by line be shown by the Label.text. Sorry If this is coming off confusing to any of you haha.
Thanks
~Tom
First of all you need to make sure that your Label has property 'AutoSize', which must be set to 'False'
Create a string array by spliting the textbox.text using Environment.NewLine.
Then you can select the proper line to display on the label from that array depending on your business logic.

How do I retain TextBox line breaks in Winforms after assigning text to a string variable?

I have a WinForms app with a multi-line textbox. This displays and retains (after loading from the DB) line break characters fine.
However if I assign the TextBox.Text value to a string variable and then re-assign the variable back to the TextBox.Text property, the line break characters are lost and replaced with a square character (can't past them here as they just paste as a line break!)
I've tried:
Replace("\n",vbcrlf)
but to no avail.
Can anyone suggest a solution?
UPDATE**
I haven't managed to fix this but have worked around it by avoiding the variable assignment. I now pass a reference to the RichTextBox and directly manipulate the text there. Note that this seems specific to the RichTextBox as I don't see the issue with a normal TextBox.
Instead of Replace("\n"' vbcrlf), you need, to use either Replace(vblf, vbcrlf), or Replace(vbcr, vbcrlf).
Just an idea:
How about fixing “\r\n” instead of “\n”?
Are you transforming the string anyway? Since something like this:
Dim s As String = TextBox1.Text
TextBox1.Text = s
works well.
textBox.AppendText("your new text" & Environment.NewLine)