Form Error when using "Break"

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 2 years and 6 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
pgessford
Posts: 7
Last visit: Fri Sep 09, 2022 10:47 am
Has voted: 1 time

Form Error when using "Break"

Post by pgessford »

Product: PowerShell Studio 2021 (64 Bit)
Build: v5.8.192
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.18363.0

I've been able to recreate this issue on a sample form with a single button. Having an issue when exit/break in an IF statement. Used the debugging features, and the error occurs immediately after the Exit statement executes.

Works fine if I run the code in the console, but when I execute as part of a form, I get an error.

Code: Select all

$form1_Load={
	#TODO: Initialize Form Controls here
	Import-Module ActiveDirectory
}

$button1_Click={
	$GetADInfo = Get-ADuser Baloney -Properties Name
	IF ($null -ne $GetADInfo)
	{
		Write-Host "$GetADInfo"
	}
	Else
	{
		Write-Host "User: $GetADInfo doesn't exist in Active Directory"
		Exit
	}
}
An error message pops up:
Unhandled Exception has occurred in a component in your application. If you click Continue, the application will ignore this error and attempt to continue. System Error.

Error Details are attached to this post.
Attachments
Error_Text.txt
(12.58 KiB) Downloaded 174 times
by brittneyr » Fri Sep 24, 2021 7:13 am
You should never use the Exit command in a GUI forum as it will generate an error.

Please look at the following post for more info:
http://www.sapien.com/forums/viewtopic.php?f=21&t=6569
Go to full post
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Form Error when using "Break"

Post by brittneyr »

[Topic moved by moderator]
Brittney
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Form Error when using "Break"

Post by brittneyr »

You should never use the Exit command in a GUI forum as it will generate an error.

Please look at the following post for more info:
http://www.sapien.com/forums/viewtopic.php?f=21&t=6569
Brittney
SAPIEN Technologies, Inc.
pgessford
Posts: 7
Last visit: Fri Sep 09, 2022 10:47 am
Has voted: 1 time

Re: Form Error when using "Break"

Post by pgessford »

Thanks for that. Simply replacing the "Exit/Break" inside of function/event with "return" resolved the issue. Appreciate the help!
This topic is 2 years and 6 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