Text Box clear Error

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 8 years and 10 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
User avatar
shamir
Posts: 124
Last visit: Thu Sep 10, 2015 1:49 am

Text Box clear Error

Post by shamir »

Error while clearing the Text box :-(


CODE: - :|

$btnClear_Click={

$textboxHomeAddress.Text = $null
}





Error: - :-(

ERROR: The property 'Text' cannot be found on this object. Verify that the property exists and can be set.
AD_User_Mgmt.psf (708): ERROR: At Line: 708 char: 2
ERROR: + $textboxHomeAddress.Text = $null
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



What is cause and a possible solution for this?

Thanks
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Text Box clear Error

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, shamir.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Text Box clear Error

Post by jvierra »

The object is not a textbox control.

To clear a textbox control we would do this:

$textbox1.Clear()
User avatar
shamir
Posts: 124
Last visit: Thu Sep 10, 2015 1:49 am

Re: Text Box clear Error

Post by shamir »

Still getting the error :-(


ERROR: You cannot call a method on a null-valued expression.
AD_User_Mgmt.psf (708): ERROR: At Line: 708 char: 2
ERROR: + $textboxHomeAddress.Clear()
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Text Box clear Error

Post by jvierra »

shamir wrote:Still getting the error :-(


ERROR: You cannot call a method on a null-valued expression.
AD_User_Mgmt.psf (708): ERROR: At Line: 708 char: 2
ERROR: + $textboxHomeAddress.Clear()
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
I repeat - your variable is not set or is not a textbox control.
The error means that $textboxHomeAddress does not exist in the scope you are in. The most common cause of this is spelling.
User avatar
Ferdinand Rios
Posts: 373
Last visit: Fri Sep 16, 2022 1:24 pm

Re: Text Box clear Error

Post by Ferdinand Rios »

As Jim said, $textbox.Clear() is the standard way of deleting text from a Textbox control, but setting the value of the Text property to $null works, too. I just tested it.

I think there's a different problem. The error indicates that the control object doesn't have a Text property (ERROR: The property 'Text' cannot be found on this object... ERROR: + $textboxHomeAddress.Text = $null). Textbox objects have a Text property, so something else is wrong.

I've run into this issue when I accidentally rename an object in the Properties pane so it looks like a different type of object, such as renaming a Form to $textboxInput so I think I'm working with a textbox, and then trying to set a Textbox-specific property, such as ReadOnly, on the Form. To detect the problem, in the Designer, click on each control and check its name in the Properties pane.

If you still need help, let us know.
F.G. Rios
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Text Box clear Error

Post by jvierra »

Ferdinand. THat is not really how it works/fails.

Look at this:
PowerShell Code
Double-click the code block to select all.
PS C:\scripts> ($null).Text
PS C:\scripts> ($null).Clear()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ ($null).Clear()
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
The error will occur on a null object when calling a method. Use auto-completion. If it doesn't work then the object is null or doesn't exist.

Your suggest is good but as often it is a misspelled name. With PS201x the rename propagates to all references so it would not usually bean issue.
This topic is 8 years and 10 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