×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help needed please: Assign variable to left hand side of an object definition

Help needed please: Assign variable to left hand side of an object definition

Help needed please: Assign variable to left hand side of an object definition

(OP)
Hello everybody,
Im after a bit of guidance/pointers please on how to do something in PowerShell....

I have a function which displays the status of system services using a traffic light graphic...

What I'm trying to do is to call the function with a number of parameters most of which are then used for substitution of variables i.e. "folder/subfolder/trafficlight"+$trafficlightnumber+".jpg" etc
however I also have a number of PictureBox's on a WPF form which I need to set the .Imagelocation tag

my "plan" is to call my function SERVICERunning "10" "green" "1" "1"
and these in turn would generate a value of $trafficLight10 Trafficligt_green.jpg $outputBox1 $ServiceCheck1

SERVICEStopped "11" "Red" "2" "6"
would generate a value of $trafficLight11 Trafficlight_red.jpg $outputBox2 $ServiceCheck6 etc

What I'd then like to be able to do is build up the following

$TrafficLightxx.ImageLocation = "\\folder\subfolder\TrafficLightRed.jpg" (Where xx is the number passed through from the function (i.e 10 or 11)
$OutputBoxy.Font = 'consolas,12' etc (where Y is 1 or 2..)

These reference WPF.PictureBoxes, RichTextBox etc and I have (so far!) 8 traffic lights, 2 output boxes

Ive tried Params and [Ref} tags and I can see in debug mode that its passing the values through but when it tries to set the associated property it reports that its not found for the object...

Any suggestions as to how to set a dynamic/pass thru value for the name of the object on the left of a definition please or if indeed it can be done..?

Sample of what Ive tried....

CODE --> PowerShell

Function ServiceRunning  {

    Param([String]$xxvariable1xx,[String]$xxvariable2xx,[String]$xxvariable3xx,[String]$xxvariable4xx)
    $WhatTrafficLight = -join('$TrafficLight',$xxvariable1xx)
    $WhatOutputBox = -join('$OutputBox',$xxvariable3xx)
    $WhatCheck = -join('$ServiceCheck',$xxvariable4xx)
    [Ref]$TrafficLight.ImageLocation = "\\folder\subfolder\Light_"+$xxvariable2xx+"_Small.png"
    [Ref]$WhatOutputBox.SelectionColor=[Drawing.Color]::Green
    [Ref]$WhatOutputBox.Font = 'Consolas,12,style=Bold'
    start-sleep -Seconds 1
    $msgText = -join([Ref]$WhatCheck[2].ToUpper(),"`t"," RUNNING","`t","(",[Ref]$WhatCheck[1],")") 
    Add-ToOutputBox1 -Message $msgText
    [System.Windows.Forms.Application]::DoEvents()
} 

Thanks.

PaulSc

RE: Help needed please: Assign variable to left hand side of an object definition

Are you looking for something like this?

CODE -->

New-Variable -name ("TrafficLight"+$xxvariablexx) 


Light travels faster than sound. That's why some people appear bright until you hear them speak.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close