Page 1 of 1

textbox appendtext

Posted: Thu Jun 10, 2021 8:42 am
by monderick
I searched for a solution for my issue with AppendText but didn't find anything.
trying to append the input from multiple text boxes into a "summary" text box but it is adding the below text marked in red for each input
i'm missing something obvious to avoid this and prevent that text from appearing, thanks for any help!


$FirstName_TextChanged = {
$firstname = $FirstName.text
}

$LastName_TextChanged={
$lastname = $LastName.text
}

Code: Select all

$buttonProvision_Click={
	#TODO: Place custom script here
	if ($radiobuttonInvited.Checked -eq $true)
	{
		$usertype = "invited"
	}
	$results.ForeColor = 'Green'
	$results.Text = "User type is '$usertype'`r`n"
	$results.AppendText("First Name is '$FirstName'`r`n")
	$results.AppendText("Last Name is '$LastName'")
}
contents of the "summary" text box:
User type is 'invited'
First Name is 'System.Windows.Forms.TextBox, Text: John'
Last Name is 'System.Windows.Forms.TextBox, Text: Smith'

Re: textbox appendtext

Posted: Thu Jun 10, 2021 9:26 am
by Alexander Riedel
PowerShell is not case sensitive.

So $lastname is the same as $LastName
$lastname = $LastName.text
So this statement assigns the text in the $LastName object to the object itself.
That'll screw things up royally.

I would recommend to name things a little differently.

I name controls with a 'Ctl' suffix. So
$LastName would become $LastNameCtl

The variable you use to assign the content to is a string. So you could name it
$strLastName or $LastNameStr to make sure when you look at the code you know what is what.
I personally use a type prefix but a suffix for generic things like 'Control', but that is a personal thing for you to develop.

Re: textbox appendtext

Posted: Thu Jun 10, 2021 9:53 am
by monderick
thanks, Alexander! pointed me in the correct direction and output is as expected now
made no alterations under the individual controls

$buttonProvision_Click = {
$FirstNameSTR = $FirstNameCTL.text
$LastNameSTR = $LastNameCTL.text

#TODO: Place custom script here
if ($radiobuttonInvited.Checked -eq $true)
{
$usertype = "invited"
}
$results.ForeColor = 'Green'
$results.Text = "User type is '$usertype'`r`n"
$results.AppendText("First Name is '$FirstNameSTR'`r`n")
$results.AppendText("Last Name is '$LastNameSTR'")

}


contents of the "summary" text box now:
User type is 'invited'
First Name is 'John'
Last Name is 'Smith'

Re: textbox appendtext

Posted: Thu Jun 10, 2021 11:20 pm
by jvierra
This is how to dereference an object:
  1. $results.Lines += 'First Name is ' + $FirstName.Text
  2. $results.Lines += 'Last Name is ' + $LastName.Text
This automatically adds a linebreak.