i have started system calculater in vb.net using process.start() method but i want to retrive it s value in textbox , how can i do that

Dani AI

Generated

Starting the system Calculator and trying to “scrape” its display is brittle and platform-dependent. Two practical, more reliable options follow (ranked by robustness), tied to earlier replies from , , and .

First — evaluate expressions inside the app. For basic arithmetic a quick approach is System.Data.DataTable.Compute; for richer needs pick a math-expression library (the mates8 approach mentioned by is an example of this tradeoff). Example (VB.NET):

Dim dt As New System.Data.DataTable()
Dim resultObj As Object = dt.Compute(expressionTextBox.Text, String.Empty)
resultTextBox.Text = resultObj.ToString()

Sanitize input, wrap in Try/Catch, and prefer a dedicated library (NCalc, Jace.NET, Flee, etc.) if functions/precision are required.

Second — read the Calculator UI via automation if the external app must be used. Windows UI Automation (System.Windows.Automation) can locate the Calculator window and read its result control via a ValuePattern. Elements, AutomationIds and window names vary by Windows build and locale, so verify the exact AutomationId with Inspect.exe or similar tools before relying on it. AutoIt (as suggested) is another pragmatic option but is similarly fragile.

Notes and cautions: inter-process UI scraping breaks with updates, localizations, or elevated processes. Where possible, compute inside the program or use a library; only use UI scraping when integration constraints make it unavoidable, and always handle failures gracefully.

Recommended Answers

All 4 Replies

Perhaps you'd like to emply 'mates8.dll' (in the attached file there is an example). There needs to be a reference to the dll and the imports statement. Then, you may parse simple expressions calling the Expression.parseExpression method.

mates8daniweb.PNG

Imports m8 = mates8

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        Try
             Dim expr As m8.Expression = m8.Expression.parseExpression(tBoxExpression.Text)
            tBoxResult.Text = expr.ToString
        Catch ex As Exception

        End Try
    End Sub
End Class

Sorry, the original file was not attached.

You can do it using AutoIt (free). If you create the AutoItX object within your program you can get the value in the calculator by

calc = "Calculator"

If aut.WinExists(calc) Then
    result = aut.WinGetText(calc)
Else
    MsgBox(calc & " window not found")
End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.