Calculate inside textbox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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
ALD Automotive
Posts: 8
Joined: Wed Feb 07, 2018 10:28 pm

Calculate inside textbox

Post by ALD Automotive » Tue Feb 20, 2018 3:18 am

Hello,
Is is possible calculate inside textbox?
Examlpe:

Code: Select all

$a = $textbox1.text
$b=$textbox2.text
$result= $a+$b
$resultTextbox.text = $result
If i wtite at textbox1 - "5" and textbox2 - "5" as result i receive "10"
But i want write at textbox1 "5+1" and textbox2 - "5" and as result receive "11"
Is it possible?

User avatar
jvierra
Posts: 13687
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Calculate inside textbox

Post by jvierra » Tue Feb 20, 2018 4:24 am

It is possible to evaluate a string.

$s = '5 * 2 + 3'
Invoke-Expression $s

User avatar
ALD Automotive
Posts: 8
Joined: Wed Feb 07, 2018 10:28 pm

Re: Calculate inside textbox

Post by ALD Automotive » Tue Feb 20, 2018 4:44 am

Thank you very much!

Locked