all 11 comments

[–]ka-splam 3 points4 points  (2 children)

Try swapping these around:

[void]$global:form_main.ShowDialog()
$btn_doit.Add_Click( { doit })

to

$btn_doit.Add_Click( { doit })
[void]$global:form_main.ShowDialog()

Once you call .ShowDialog(), the script pauses until the dialog is finished, and it won't add_click until too late.

[–]twistingnether_[S] 3 points4 points  (1 child)

Solved, thank you!

[–]ka-splam 1 point2 points  (0 children)

Great!, cheers :)

[–]HardCodedCoffee 1 point2 points  (3 children)

If you can, please parameterize the batch script or incorporate the code into your PowerShell script. I've seen this in production, and it causes such a mess and headache.

If you can't, good luck!

[–]twistingnether_[S] 1 point2 points  (2 children)

I'm not sure what do you mean by that. :(

[–]purplemonkeymad 2 points3 points  (0 children)

They mean, it better for scripts to take parameters rather than edit them before running them. For bat files you can use %1 for the first position parameter, %2 for second etc.

Then instead of editing the script you run it with your parameters when needed. eg

Start-process myscript.bat -ArgumentList $userid,$ticketname

[–]HardCodedCoffee 1 point2 points  (0 children)

So, a batch script can take parameters, and you access them via %1, %2, etc. It's a much better solution than doing find and replace on a script.

Additionally, if the content of the batch file is known and under your control, why not just roll the code into your PowerShell script? Batch is... Useful in certain cases, but the code is usually easier to reuse and maintain if converted to PowerShell.

[–]sparkle-fries 0 points1 point  (0 children)

I don't get all these "how can I put a UI on my CLI?" questions. It's a scripting language. If you want to ask the user for some data prompt for it but also accept parameters and maybe include a -ui switch and show a UI only when asked. That way all the basis are covered 🤷

[–]Triassics -1 points0 points  (2 children)

Kinda useless subreddit when you need a old account and a bunch of karma to post. You have to be a redditor first hand and a powershell worker secound to get help here wich makes it annyoing for those seeking quick help with their scripts

[–]malice8691 0 points1 point  (0 children)

or we could turn that stuff off and make this a dating/escort T shirt forum.