Simple calculator build (have code) need help

ExcelTheCell

Board Regular
Joined
Nov 14, 2010
Messages
158
Well guys i'm not sure will you be able to help because this is code that i made in visual basic studio.. But i have found many similarity's between VBA in Excel and this one.

I'm tring to create simple calculator
textbox1 is number
textbox2 is agregate function (+ or - or * or /)
textbox3 is number
and textbox 4 gives result

here is the code:

HTML:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim number1 As Integer
        Dim number2 As Integer
        Dim Number3 As Integer
        Dim sign As String

        number1 = TextBox1.Text
        sign = TextBox2.Text
        number2 = TextBox3.Text
        Number3 = number1 & sign & number2
        TextBox4.Text = Number3

    End Sub
End Class

Example:
number1= integer = 1
sign= string = +
Number2= integer=2
Numberr=3

Anly idea??
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
not sure you can ADD with text

try

number2 = TextBox3.Text

as

number2 = TextBox3.value
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Private Sub CommandButton1_Click()
TextBox4.Value = Evaluate(Val(TextBox1.Text) & TextBox2.Text & Val(TextBox3.Text))
End Sub

N.B. no error check!!
 

ExcelTheCell

Board Regular
Joined
Nov 14, 2010
Messages
158
Tnx Vog that solved the problem...

[EDIT] oh no it isn't now what ever u write + or - or * it will give me result 3.. but we have some progress
 
Last edited:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,713
Messages
5,833,272
Members
430,201
Latest member
Deepakpilla36

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top