Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:55:48+00:00 2026-06-18T09:55:48+00:00

I am learning Powershell and attempting to create a GUI interface like the example

  • 0

I am learning Powershell and attempting to create a GUI interface like the example here.

However, when I run this as it is, $x is never defined. Any idea what I could be doing wrong? I know it has something to do with:

$OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close()})

Because if I change it to:

$OKButton.Add_Click({Write-Host "worked";$objForm.Close()})

It does return worked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:55:49+00:00Added an answer on June 18, 2026 at 9:55 am

    Your actionblock is running in a seperate local scope. To modify a global(session-wide) variable, use a scope-modifier($global:varname). E.g.:

    $OKButton.Add_Click({$global:x=$objListBox.SelectedItem;$objForm.Close()})
    

    More about scopes at Technet – about_Scopes (or write Get-Help about_scopes in PowerShell)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning PowerShell and one good friend recommended me this beautiful article about binary
Learning Jquery here and I would like to show my SQL table on my
I'm early on in my PowerShell learning, and I'm wondering if there are some
I trying to write a PowerShell script (learning at the same time). I have
Learning some VBA. So far, I've constructed this piece of code which should allow
learning FTL here. I'm trying to get add a query string on my FTL
I've started learning VBScript because of PowerShell, but I want to know if I
I'm particularly interested in Windows PowerShell , but here's a somewhat more general complaint:
In PowerShell I find myself doing this kind of thing over and over again
Learning about Explicit Cursors and trying to create my frst one.: SET SERVEROUTPUT ON

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.