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??
 

Some videos you may like

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

Moderator
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:

Watch MrExcel Video

Forum statistics

Threads
1,109,202
Messages
5,527,388
Members
409,759
Latest member
KCH

This Week's Hot Topics

Top