User Input not working.

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 1 year and 8 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
mark012492
Posts: 2
Last visit: Tue Mar 05, 2024 5:55 am

User Input not working.

Post by mark012492 »

New to PowerShell Studio.

I have a simple form (psf) to test with a input box (textbox1) and a button. For some reason I can't get the the text that was entered to display. When I enter text into textbox1 and click the button "Clicked" displays but not the text. Is there another way to display input? I have a few other forms where this works.

Thanks in advance!

PowerShell Studio 2022

Code: Select all

$form1_Load={
	#TODO: Initialize Form Controls here
}
$button1_Click={
	#TODO: Place custom script here
	[string]$textbox1.Text
	Write-Host "Clicked"
}
Results

Code: Select all

>> Platform: V5 64Bit (STA) (Forced)
Clicked
Clicked
Clicked
Clicked

*** PowerShell Script finished. ***
>> Execution time: 00:00:11
>> Script Ended
mark012492
Posts: 2
Last visit: Tue Mar 05, 2024 5:55 am

Re: User Input not working.

Post by mark012492 »

Using Write-Host "$($textbox1.Text)" works.

Code: Select all

$form1_Load={
	#TODO: Initialize Form Controls here
	
}

$button1_Click = {
	#TODO: Place custom script here
	Write-Host "Clicked"
	Write-Host "$($textbox1.Text)"
}


Output

Code: Select all

>> Platform: V5 64Bit (STA) (Forced)
Clicked
User Input
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: User Input not working.

Post by jvierra »

That is how PowerShell works. There is no default output from the pipeline for code run in a form.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: User Input not working.

Post by jvierra »

Note that Write-Host is not normal output command. It is a command that can nly output to a console and it cannot be redirected using normal methods. And yes, it is the only way to do direct output to a console from a form and may not work all of the time.

I recommend getting one of the excellent books on PowerShell and learning PowerShell beyond just guessing. Also review the articles on this website on how to use forms and controls with PowerShell.
This topic is 1 year and 8 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