Author Posts

April 17, 2018 at 10:06 pm

I am quite new to Powershell so apologies if the below is of poor quality/anything missed. I am trying to update a textbox value on button click which will be the result of data entered into different text boxes. My current function is producing ".text" in the GUI and not the .text property of the text box objects that I want to show.

Below is the function:

function PopulateUserDetails
        param (
	$UsernameTextBox.text = "$SurnameTextBox.text"
	$EmailAddressTextBox.text = "$FirstNameTextBox.text + $SurnameTextBox.text"

& below is the relevant object code:

$FirstNameTextBox = New-Object System.Windows.Forms.TextBox

$PopulateUserDetails = New-Object System.Windows.Forms.Button
$PopulateUserDetails.Text = 'Populate User Details'

Where surname text box has the same properties as first name text box.

From the code above, I want my statement to when button click "Populate user details", update the user name and email address text boxes to $Firstname and $Firstname+$surname respectively, but it is showing as ".text" and ".text .text". How can I reference the firstname and surname values that the user has entered? Also, if achievable, is there a way to 'Auto' update the value of the textbox in real-time as the user is entering them?

Kind regards

April 17, 2018 at 10:08 pm

This is the problem:


Only $SurnameTextBox is read as a variable name. Use a subexpression instead:

"$( $SurnameTextBox.text )"