Textbox Output

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 3 years and 11 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
craigjb
Posts: 11
Last visit: Mon Oct 05, 2020 7:31 am

Textbox Output

Post by craigjb »

Hi,

I am trying to display the output of my PowerShell function to a textbox. The desired output is "ctest". However, I receive the following

Code: Select all

C-System.Windows.Forms.TextBox, Text: Test.Text
I'm trying to populate the output of the stored variable username in textbox3 via the below

Code: Select all

$textbox3.Text = "$($userName)"
Any help is very appreciated. Thank you
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Textbox Output

Post by jvierra »

What you are saying tells me that "$username" is not a value but it is another textbox obect.
The correct way to assign a textbox from a variable is the following:

$textbox3.Text = $userName

What shows up depends on how you set $username,
User avatar
craigjb
Posts: 11
Last visit: Mon Oct 05, 2020 7:31 am

Re: Textbox Output

Post by craigjb »

Hi Jvierra,

$username contains the stored value of the output of my function. The value when using PowerShell_ISE is "CTest". However, when writing it to a textbox in PowerShell Studio it is C-System.Windows.Forms.TextBox, Text: Test.Text. I'm trying to figure out how to display it correctly.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Textbox Output

Post by jvierra »

How can we know without knowing what your function is doing? Somewhere you are doing something wrong. Have you stepped through this in the debugger?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Textbox Output

Post by jvierra »

Here is an example of what you are doing and why?
Annotation 2020-04-08 173438.png
Annotation 2020-04-08 173438.png (9.29 KiB) Viewed 2786 times
User avatar
craigjb
Posts: 11
Last visit: Mon Oct 05, 2020 7:31 am

Re: Textbox Output

Post by craigjb »

I don't believe the function is the issue. There is no errors being thrown. Its clearly grabbing the correct data, but adding in the non-bold parts.
C-System.Windows.Forms.TextBox, Text: Test.Text

This issue is very similar to the below. We just need to put this into a GUI to hand off.

viewtopic.php?t=6371

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

Re: Textbox Output

Post by jvierra »

We can also do this to show you what your are doing:

$textbox3.Text = $userName.Text

I can make that happen very easily:
Annotation 2020-04-08 174032.png
Annotation 2020-04-08 174032.png (10.63 KiB) Viewed 2786 times
See - same output you are getting.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Textbox Output

Post by jvierra »

craigjb wrote: Wed Apr 08, 2020 2:38 pm I don't believe the function is the issue. There is no errors being thrown. Its clearly grabbing the correct data, but adding in the non-bold parts.
C-System.Windows.Forms.TextBox, Text: Test.Text

This issue is very similar to the below. We just need to put this into a GUI to hand off.

viewtopic.php?t=6371

Thanks
Sorry but that has nothing to do with what you are seeing. It is a completely different issue.
This topic is 3 years and 11 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