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.
Post Reply
pgessford
Posts: 4
Last visit: Wed Sep 29, 2021 9:42 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 54 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: 893
Last visit: Mon Oct 18, 2021 6:45 am
Answers: 20
Been upvoted: 17 times

Re: Form Error when using "Break"

Post by brittneyr »

[Topic moved by moderator]
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
brittneyr
Site Admin
Posts: 893
Last visit: Mon Oct 18, 2021 6:45 am
Answers: 20
Been upvoted: 17 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 Ryn
SAPIEN Technologies, Inc.

pgessford
Posts: 4
Last visit: Wed Sep 29, 2021 9:42 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!

Post Reply