Variable and .visible fonction

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
Locked
User avatar
adminmicro
Posts: 11
Joined: Thu Oct 03, 2013 11:51 am

Variable and .visible fonction

Post by adminmicro »

Hello,

I have a loop to test file dates on a server list
For each server I want to display an image in the GUI PowerShell Studio

My script in my loop is :
$icoActivation = '$' + $node + 'KoStatus'
$icoActivation.Visible = $true
And the error is : The properties "Visible" is not existe for this object

Do you have an idea for me?

Regards

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Variable and .visible fonction

Post by jvierra »

That is correct. The variable is a string and strings do not have a "visible" property.

$icoActivation = '$' + $node + 'KoStatus'
$icoActivation.GetType()


Why would you want a string to be visible. I suspect you have an icon object that is what you really want to make visible,

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Variable and .visible fonction

Post by jvierra »

Your use of $node seems to indicate that this is a TreeView question. See the following article section for help using images with nodes.

https://info.sapien.com/index.php/guis/ ... #imagelist

User avatar
adminmicro
Posts: 11
Joined: Thu Oct 03, 2013 11:51 am

Re: Variable and .visible fonction

Post by adminmicro »

Thanks for your help

$icoActivation.Visible is a picturebox
I have a picturebox for each node (Picturebox for services OK, Picturebox for service Ko)
The name type for the picturebox is %ServerName%SrvOk (For exemple Poller01srvok)

Since I'm using a foreach loop, I'm looking for how to indicate the variable with the visible function

foreach ($node in $listAPE)
{
$sqlnetAPE = Get-Item ......
if ($sqlnetAPE -eq $sqlnet)
{
$icoActivation = '$' + $node + 'srvok'
$icoActivation.Visible = $true
}
else
{
$icoActivation = '$' + $node + 'srvKo'
$icoActivation.Visible = $true
}
}

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Variable and .visible fonction

Post by jvierra »

The following line turns the picturebox into a string.
$icoActivation = '$' + $node + 'srvok'

To find a control by string name:


$form.Controls[$node + 'srvok'].Visible = $true

User avatar
adminmicro
Posts: 11
Joined: Thu Oct 03, 2013 11:51 am

Re: Variable and .visible fonction

Post by adminmicro »

Thanks for your help

It works very well

Just for information, be careful to put the name of the form so that it works ($form for my is $formservicesstatus)

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Variable and .visible fonction

Post by jvierra »

adminmicro wrote:
Thu Jan 23, 2020 7:53 am
Thanks for your help

It works very well

Just for information, be careful to put the name of the form so that it works ($form for my is $formservicesstatus)
There is no way for us to know the name of your form.

User avatar
adminmicro
Posts: 11
Joined: Thu Oct 03, 2013 11:51 am

Re: Variable and .visible fonction

Post by adminmicro »

No problem, This is just a clarification for other readers.
Regards

Locked