assing a multiline value to a textbox

Ask your Windows 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.
Locked
User avatar
sunlister
Posts: 1
Joined: Fri Dec 15, 2017 7:02 am

assing a multiline value to a textbox

Post by sunlister » Fri Dec 15, 2017 7:13 am

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
Site Admin
Posts: 97
Joined: Sun Mar 03, 2013 12:42 pm

Re: assing a multiline value to a textbox

Post by mxtrinidad » Fri Dec 15, 2017 11:37 am

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.

:)

User avatar
jvierra
Posts: 12088
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: assing a multiline value to a textbox

Post by jvierra » Fri Dec 15, 2017 12:57 pm

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 7 times

User avatar
cody m
Site Admin
Posts: 105
Joined: Thu Jun 01, 2017 7:20 am

Re: assing a multiline value to a textbox

Post by cody m » Fri Dec 15, 2017 2:09 pm

I also can not reproduce the error that Sunlister is getting.
Cody McCants
SAPIEN Technologies, Inc.

User avatar
mxtrinidad
Site Admin
Posts: 97
Joined: Sun Mar 03, 2013 12:42 pm

Re: assing a multiline value to a textbox

Post by mxtrinidad » Fri Dec 15, 2017 4:26 pm

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 604 times

User avatar
jvierra
Posts: 12088
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: assing a multiline value to a textbox

Post by jvierra » Fri Dec 15, 2017 5:27 pm

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.

Locked