[beginner] calling a function?

Jul 23, 2011 at 7:39 AM

Hi,

I've discovered ShowUI this week, and I really like the approach! Thanks so much for it.

Unfortunately, I don't know C#, or WPF yet, but I use PowerShell every day for simple management.

Could you please give me a basic example on how to call a function, like so:

Import-Module ShowUI

function fn($x){ Write-Host "hi $x" }

New-Button "click" -on_Click { fn } -Show

as this one is clearly wrong!

Thx in advance

Regards,

jucg

Developer
Jul 23, 2011 at 1:22 PM

Your example works for me. I copied and pasted it to the console and get a window and output when I click the button.

Do you get an error? No Window?

Doug

Jul 25, 2011 at 8:17 AM

Hi,

thanks a lot for your reply. Indeed, I made new trials, and it's working!! But not always as sometimes, the GUI doesn't show up. It simply opens a new powershell menu in the task bar with submenus (execute as admin, import system modules, etc.)

Cannot say more...

Regards

jucg

Developer
Jul 25, 2011 at 11:34 PM

jucg, I am having trouble understanding. I need a little more info.

 

Doug

Jul 26, 2011 at 9:12 AM

Hi, 

thank you for responding. As mentionned, I'm a beginner and don't want to waste your time (better dedicated to ShowUI ;-)

I'm running Powershell -STA in Console2. The first time I a launch the "hi" script:

Import-Module ShowUI

function fn { Write-Host "hi" }

New-Button "click" -on_Click { fn } -Show

a Powershell icon appears in the task bar. I have to close it, and the second time, the button appears, and the function is trigger on_Click. I've repeated a few times on win7.

This behaviour doesn't appear in default PS Shell, nor in ISE. So might be related to Console2 only.

I realized that I may have used Write-Host's alias ("echo") in my function, and this doesn't work in any environment.

I think this is solved!

Good luck with this very nice project

jucg

 

Developer
Jul 26, 2011 at 12:07 PM

Thanks for the update jucg. It's good to post questions. ShowUI is new enough that there may be bugs.

Echo is aliased to Write-Host so that is not a problem. It sounds like it may be related to Console2 and I don't have that installed to try it against.

Doug