assing a multiline value to a textbox

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sunlister
Posts: 1
Last visit: Fri Dec 15, 2017 12:01 pm

assing a multiline value to a textbox

Post by sunlister »

Hi,
I'm trying to assing a multiline value to a textbox but it put everything on the same line.

The multiline property of the textbox is at True.
When I do a write-host of my variable it show on differents lines.
$example = "Hi
Car
Today"

$I_INFO_SUPP.text = $example

The result is "HiCarToday"

Thanks
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: assing a multiline value to a textbox

Post by mxtrinidad »

Simple fix!

You need to use the Here-String text format the following way:

$example = @"Hi
Car
Today
"@

For more information look at the following link: https://technet.microsoft.com/en-us/lib ... 92792.aspx

Otherwise the previous format will be understood as a one line string no matter how you'll break it within the double (or single) quotes.

:)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: assing a multiline value to a textbox

Post by jvierra »

I do not see that at all. Using sunlister's example and assigning to a multiline textbox produces individual lines.

See attached example.
Attachments
Test-TextBoxFormats.psf
(22.87 KiB) Downloaded 125 times
cody m

Re: assing a multiline value to a textbox

Post by cody m »

I also can not reproduce the error that Sunlister is getting.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: assing a multiline value to a textbox

Post by mxtrinidad »

The only way I can replicate the issue would be by leaving the text box multiline property as "False". Otherwise setting it to "True" and resizing the textbox then it will work with either single, double quotes, and here-string format.
Multiline_2017-12-15_18-19-35.png
Multiline_2017-12-15_18-19-35.png (11.63 KiB) Viewed 2889 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: assing a multiline value to a textbox

Post by jvierra »

I suspect t that this could indicate that the OP is setting the multiline property at the wrong time although, if the box is expanded then it must be set to $true.

There is also a possible problem using Net 1.0 or 2.0. All updates to Net 2.0 seem to have fixed some of the odd behaviors of the initial versions. I have no way of testing so this is just from memory.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked