Hello,

I have four textboxes in my calculator. Textbox 1, Textbox 2, Textbox 3 (acts for the Operand) and Textbox 4 (the result).

I have a button called Result and when clicked, I want the result to show in the 'Textbox 4'. How would I go about that.

Also, when entered an alphabetic character into any of the boxes, it should be able to prompt a message saying ' it is an invalid character' and when entered numbers in the Textbox 3 (Operand), it should also prompt a message saying it is 'invalid'

Can anyone help?

Thanks

Recommended Answers

All 22 Replies

To make the result show in textbox 4, have textbox4.text = (put the result here). To prevent any alphabethic characters, use the isnumeric function.

if not isnumeric(textbox1.text) then
[INDENT]msgbox("Invalid")
exit sub[/INDENT]
end if

If you have any more questions, don't hesitate to ask!

Hi,

Thanks for the quick response. Since I am totally new to VB.net, I have so many questions in my mind. First of all, if I were to restrict the user from tying an alphabet characters, how would I go about that. In other words, they can only type numbers only in two of the textboxes i.e. textbox1 and textbox2 and only the operands (+, -, /,*) in textbox3. How would I do that.?

Thank you so much!

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If Len(TextBox1.Text) > 0 Then
            If Not IsNumeric(TextBox1.Text) Then
                TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.Length - 1, 1)
            End If
        End If
    End Sub

Basically, it looks at the text in the text box as soon as there is a change to the text. if it isn't numeric, it deletes the character. You need to make sure the length of the textbox text is greater than zero (at least 1), because if someone enters, say "a" as the first digit, it would otherwise delete the "a" and then that triggers another change, leaving the box empty which is not numeric. but it works fairly well.

if you need more help, feel free to ask.

use this following code, this code will handle string input (include special character). if u type a numeric in textbox it will type but if u type string,char or anything else except numeric it will not type in text box.

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
        Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
            e.Handled = True
        End If
        If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
            e.Handled = False
        End If
    End Sub

Ok. all for the best.

Hi,

Thanks for that code. It worked fine. Sorry to bother again, but if I were to use a Select.. Case function, where would I implement it and how? Is it possible to implement it on the Textbox 3, which is the operator where the users type the signs (+, _ ...)?

Thanks again in advance!

if you need more help, feel free to ask.

Hi,

Thanks for that code. It worked fine. Sorry to bother again, but if I were to use a Select.. Case function, where would I implement it and how? Is it possible to implement it on the Textbox 3, which is the operator where the users type the signs (+, _ ...)?

Thanks again in advance!

Thanks for that code. It worked fine. Sorry to bother again, but if I were to use a Select.. Case function, where would I implement it and how?

this following code modified from my post which it using if..then..else to select...case :

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Select Case Microsoft.VisualBasic.Asc(e.KeyChar)
            Case 48 To 57, 8
                'Let these key codes pass through
            Case Else
                e.Handled = True
        End Select
    End Sub

Is it possible to implement it on the Textbox 3, which is the operator where the users type the signs (+, _ ...)?

why you don't use combo box to implement operator, so user just select the operator in combo box that they want to use...

Hi,

I have a quick question, I have this code on the combobox and I wonder how I should change this to the Select..Case format:

'If the user select a Minus sign on the combobox then
If combobox.Text = "-" Then
TextboxResult.Text = (Convert.ToInt32(txtNumber1.Text) - Convert.ToInt32(txtNumber2.Text)).ToString()
End If

Thanks

Really appreciate your help!

your if..else will looks like this in select...case

Private Sub ComboOperan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboOperan.SelectedIndexChanged
        Select Case ComboOperan.SelectedItem
            Case "+"
                MsgBox((Convert.ToInt32(txtNumber1.Text) + Convert.ToInt32(txtNumber2.Text)))
            Case "-"
                MsgBox((Convert.ToInt32(txtNumber1.Text) - Convert.ToInt32(txtNumber2.Text)))
            Case "*"
                MsgBox((Convert.ToInt32(txtNumber1.Text) * Convert.ToInt32(txtNumber2.Text)))
            Case "/"
                MsgBox((Convert.ToInt32(txtNumber1.Text) / Convert.ToInt32(txtNumber2.Text)))
        End Select
    End Sub

You can change Msgbox with your TextboxResult.Text...
OK. Hope This Helps..

commented: nice code +1

hi, i am new to this site so please be gentle. The problem i have is described below, and i wrote the code in VisualStudio 2005

I am trying to make a calculator. The problem i have is that the value in the 1st textbox assigns to the first variable (used for 1st number), the value in the 2nd textbox assigns to the sign variable (to store the operator, - + / *) but then for some reason i cannot add anything into the 3rd textbox which should assign the 2nd variable (used for 2nd number)..... i will post all the code below including a screenshot of the form for you to see.

please help me because i have tried to work this out for a few days and i cant see anything wrong with the code but for some reason it isnt working properly (like i said, it wont add anything to the 2nd variable)

btw, i am aware that the extra functions such as % or M+ and things like that arent working or even coded yet but thats because i still need the 2nd variable to work 1st before any of that can be done. all of your help is very much appreciated. Thanks to everyone who helps.

form:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form


'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub






'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer


'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtDisplay = New System.Windows.Forms.TextBox
Me.btn0 = New System.Windows.Forms.Button
Me.btn2 = New System.Windows.Forms.Button
Me.btn3 = New System.Windows.Forms.Button
Me.btn1 = New System.Windows.Forms.Button
Me.btn4 = New System.Windows.Forms.Button
Me.btn5 = New System.Windows.Forms.Button
Me.btn6 = New System.Windows.Forms.Button
Me.btn9 = New System.Windows.Forms.Button
Me.btn8 = New System.Windows.Forms.Button
Me.btn7 = New System.Windows.Forms.Button
Me.btnDot = New System.Windows.Forms.Button
Me.btnEquals = New System.Windows.Forms.Button
Me.btnPlus = New System.Windows.Forms.Button
Me.btnMinus = New System.Windows.Forms.Button
Me.btnMultiply = New System.Windows.Forms.Button
Me.btnDivide = New System.Windows.Forms.Button
Me.btnMAdd = New System.Windows.Forms.Button
Me.btnMErase = New System.Windows.Forms.Button
Me.btnMRecall = New System.Windows.Forms.Button
Me.btnSquareRt = New System.Windows.Forms.Button
Me.btnPercent = New System.Windows.Forms.Button
Me.btnCE = New System.Windows.Forms.Button
Me.btnNegative = New System.Windows.Forms.Button
Me.txtSign = New System.Windows.Forms.TextBox
Me.txtAnswer = New System.Windows.Forms.TextBox
Me.txtDisplay2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'txtDisplay
'
Me.txtDisplay.Location = New System.Drawing.Point(36, 117)
Me.txtDisplay.Name = "txtDisplay"
Me.txtDisplay.ReadOnly = True
Me.txtDisplay.Size = New System.Drawing.Size(372, 20)
Me.txtDisplay.TabIndex = 0
'
'btn0
'
Me.btn0.Location = New System.Drawing.Point(120, 350)
Me.btn0.Name = "btn0"
Me.btn0.Size = New System.Drawing.Size(36, 29)
Me.btn0.TabIndex = 0
Me.btn0.Text = "0"
Me.btn0.UseVisualStyleBackColor = True
'
'btn2
'
Me.btn2.Location = New System.Drawing.Point(162, 315)
Me.btn2.Name = "btn2"
Me.btn2.Size = New System.Drawing.Size(36, 29)
Me.btn2.TabIndex = 2
Me.btn2.Text = "2"
Me.btn2.UseVisualStyleBackColor = True
'
'btn3
'
Me.btn3.Location = New System.Drawing.Point(204, 315)
Me.btn3.Name = "btn3"
Me.btn3.Size = New System.Drawing.Size(36, 29)
Me.btn3.TabIndex = 3
Me.btn3.Text = "3"
Me.btn3.UseVisualStyleBackColor = True
'
'btn1
'
Me.btn1.Location = New System.Drawing.Point(120, 315)
Me.btn1.Name = "btn1"
Me.btn1.Size = New System.Drawing.Size(36, 29)
Me.btn1.TabIndex = 1
Me.btn1.Text = "1"
Me.btn1.UseVisualStyleBackColor = True
'
'btn4
'
Me.btn4.Location = New System.Drawing.Point(120, 280)
Me.btn4.Name = "btn4"
Me.btn4.Size = New System.Drawing.Size(36, 29)
Me.btn4.TabIndex = 4
Me.btn4.Text = "4"
Me.btn4.UseVisualStyleBackColor = True
'
'btn5
'
Me.btn5.Location = New System.Drawing.Point(162, 280)
Me.btn5.Name = "btn5"
Me.btn5.Size = New System.Drawing.Size(36, 29)
Me.btn5.TabIndex = 5
Me.btn5.Text = "5"
Me.btn5.UseVisualStyleBackColor = True
'
'btn6
'
Me.btn6.Location = New System.Drawing.Point(204, 280)
Me.btn6.Name = "btn6"
Me.btn6.Size = New System.Drawing.Size(36, 29)
Me.btn6.TabIndex = 6
Me.btn6.Text = "6"
Me.btn6.UseVisualStyleBackColor = True
'
'btn9
'
Me.btn9.Location = New System.Drawing.Point(204, 245)
Me.btn9.Name = "btn9"
Me.btn9.Size = New System.Drawing.Size(36, 29)
Me.btn9.TabIndex = 9
Me.btn9.Text = "9"
Me.btn9.UseVisualStyleBackColor = True
'
'btn8
'
Me.btn8.Location = New System.Drawing.Point(162, 245)
Me.btn8.Name = "btn8"
Me.btn8.Size = New System.Drawing.Size(36, 29)
Me.btn8.TabIndex = 8
Me.btn8.Text = "8"
Me.btn8.UseVisualStyleBackColor = True
'
'btn7
'
Me.btn7.Location = New System.Drawing.Point(120, 245)
Me.btn7.Name = "btn7"
Me.btn7.Size = New System.Drawing.Size(36, 29)
Me.btn7.TabIndex = 7
Me.btn7.Text = "7"
Me.btn7.UseVisualStyleBackColor = True
'
'btnDot
'
Me.btnDot.Location = New System.Drawing.Point(162, 350)
Me.btnDot.Name = "btnDot"
Me.btnDot.Size = New System.Drawing.Size(36, 29)
Me.btnDot.TabIndex = 10
Me.btnDot.Text = "."
Me.btnDot.UseVisualStyleBackColor = True
'
'btnEquals
'
Me.btnEquals.Location = New System.Drawing.Point(204, 350)
Me.btnEquals.Name = "btnEquals"
Me.btnEquals.Size = New System.Drawing.Size(36, 29)
Me.btnEquals.TabIndex = 11
Me.btnEquals.Text = "="
Me.btnEquals.UseVisualStyleBackColor = True
'
'btnPlus
'
Me.btnPlus.Location = New System.Drawing.Point(284, 315)
Me.btnPlus.Name = "btnPlus"
Me.btnPlus.Size = New System.Drawing.Size(36, 64)
Me.btnPlus.TabIndex = 12
Me.btnPlus.Text = "+"
Me.btnPlus.UseVisualStyleBackColor = True
'
'btnMinus
'
Me.btnMinus.Location = New System.Drawing.Point(284, 280)
Me.btnMinus.Name = "btnMinus"
Me.btnMinus.Size = New System.Drawing.Size(36, 29)
Me.btnMinus.TabIndex = 13
Me.btnMinus.Text = "-"
Me.btnMinus.UseVisualStyleBackColor = True
'
'btnMultiply
'
Me.btnMultiply.Location = New System.Drawing.Point(284, 245)
Me.btnMultiply.Name = "btnMultiply"
Me.btnMultiply.Size = New System.Drawing.Size(36, 29)
Me.btnMultiply.TabIndex = 14
Me.btnMultiply.Text = "*"
Me.btnMultiply.UseVisualStyleBackColor = True
'
'btnDivide
'
Me.btnDivide.Location = New System.Drawing.Point(284, 210)
Me.btnDivide.Name = "btnDivide"
Me.btnDivide.Size = New System.Drawing.Size(36, 29)
Me.btnDivide.TabIndex = 15
Me.btnDivide.Text = "/"
Me.btnDivide.UseVisualStyleBackColor = True
'
'btnMAdd
'
Me.btnMAdd.Location = New System.Drawing.Point(204, 210)
Me.btnMAdd.Name = "btnMAdd"
Me.btnMAdd.Size = New System.Drawing.Size(36, 29)
Me.btnMAdd.TabIndex = 16
Me.btnMAdd.Text = "M+"
Me.btnMAdd.UseVisualStyleBackColor = True
'
'btnMErase
'
Me.btnMErase.Location = New System.Drawing.Point(162, 210)
Me.btnMErase.Name = "btnMErase"
Me.btnMErase.Size = New System.Drawing.Size(36, 29)
Me.btnMErase.TabIndex = 17
Me.btnMErase.Text = "M-"
Me.btnMErase.UseVisualStyleBackColor = True
'
'btnMRecall
'
Me.btnMRecall.Location = New System.Drawing.Point(109, 210)
Me.btnMRecall.Name = "btnMRecall"
Me.btnMRecall.Size = New System.Drawing.Size(47, 29)
Me.btnMRecall.TabIndex = 18
Me.btnMRecall.Text = "MRC"
Me.btnMRecall.UseVisualStyleBackColor = True
'
'btnSquareRt
'
Me.btnSquareRt.Location = New System.Drawing.Point(204, 175)
Me.btnSquareRt.Name = "btnSquareRt"
Me.btnSquareRt.Size = New System.Drawing.Size(36, 29)
Me.btnSquareRt.TabIndex = 21
Me.btnSquareRt.Text = "√"
Me.btnSquareRt.UseVisualStyleBackColor = True
'
'btnPercent
'
Me.btnPercent.Location = New System.Drawing.Point(162, 175)
Me.btnPercent.Name = "btnPercent"
Me.btnPercent.Size = New System.Drawing.Size(36, 29)
Me.btnPercent.TabIndex = 20
Me.btnPercent.Text = "%"
Me.btnPercent.UseVisualStyleBackColor = True
'
'btnCE
'
Me.btnCE.Location = New System.Drawing.Point(109, 175)
Me.btnCE.Name = "btnCE"
Me.btnCE.Size = New System.Drawing.Size(47, 29)
Me.btnCE.TabIndex = 19
Me.btnCE.Text = "CE"
Me.btnCE.UseVisualStyleBackColor = True
'
'btnNegative
'
Me.btnNegative.Location = New System.Drawing.Point(284, 175)
Me.btnNegative.Name = "btnNegative"
Me.btnNegative.Size = New System.Drawing.Size(36, 29)
Me.btnNegative.TabIndex = 22
Me.btnNegative.Text = "+/-"
Me.btnNegative.UseVisualStyleBackColor = True
'
'txtSign
'
Me.txtSign.Location = New System.Drawing.Point(36, 91)
Me.txtSign.Name = "txtSign"
Me.txtSign.ReadOnly = True
Me.txtSign.Size = New System.Drawing.Size(372, 20)
Me.txtSign.TabIndex = 23
'
'txtAnswer
'
Me.txtAnswer.Location = New System.Drawing.Point(36, 12)
Me.txtAnswer.Name = "txtAnswer"
Me.txtAnswer.ReadOnly = True
Me.txtAnswer.Size = New System.Drawing.Size(372, 20)
Me.txtAnswer.TabIndex = 25
'
'txtDisplay2
'
Me.txtDisplay2.Location = New System.Drawing.Point(36, 65)
Me.txtDisplay2.Name = "txtDisplay2"
Me.txtDisplay2.ReadOnly = True
Me.txtDisplay2.Size = New System.Drawing.Size(372, 20)
Me.txtDisplay2.TabIndex = 26
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(436, 405)
Me.Controls.Add(Me.txtDisplay2)
Me.Controls.Add(Me.txtAnswer)
Me.Controls.Add(Me.txtSign)
Me.Controls.Add(Me.btnNegative)
Me.Controls.Add(Me.btnSquareRt)
Me.Controls.Add(Me.btnPercent)
Me.Controls.Add(Me.btnCE)
Me.Controls.Add(Me.btnMRecall)
Me.Controls.Add(Me.btnMErase)
Me.Controls.Add(Me.btnMAdd)
Me.Controls.Add(Me.btnDivide)
Me.Controls.Add(Me.btnMultiply)
Me.Controls.Add(Me.btnMinus)
Me.Controls.Add(Me.btnPlus)
Me.Controls.Add(Me.btnEquals)
Me.Controls.Add(Me.btnDot)
Me.Controls.Add(Me.btn9)
Me.Controls.Add(Me.btn8)
Me.Controls.Add(Me.btn7)
Me.Controls.Add(Me.btn6)
Me.Controls.Add(Me.btn5)
Me.Controls.Add(Me.btn4)
Me.Controls.Add(Me.btn1)
Me.Controls.Add(Me.btn3)
Me.Controls.Add(Me.btn2)
Me.Controls.Add(Me.btn0)
Me.Controls.Add(Me.txtDisplay)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()


End Sub
Friend WithEvents txtDisplay As System.Windows.Forms.TextBox
Friend WithEvents btn0 As System.Windows.Forms.Button
Friend WithEvents btn2 As System.Windows.Forms.Button
Friend WithEvents btn3 As System.Windows.Forms.Button
Friend WithEvents btn1 As System.Windows.Forms.Button
Friend WithEvents btn4 As System.Windows.Forms.Button
Friend WithEvents btn5 As System.Windows.Forms.Button
Friend WithEvents btn6 As System.Windows.Forms.Button
Friend WithEvents btn9 As System.Windows.Forms.Button
Friend WithEvents btn8 As System.Windows.Forms.Button
Friend WithEvents btn7 As System.Windows.Forms.Button
Friend WithEvents btnDot As System.Windows.Forms.Button
Friend WithEvents btnEquals As System.Windows.Forms.Button
Friend WithEvents btnPlus As System.Windows.Forms.Button
Friend WithEvents btnMinus As System.Windows.Forms.Button
Friend WithEvents btnMultiply As System.Windows.Forms.Button
Friend WithEvents btnDivide As System.Windows.Forms.Button
Friend WithEvents btnMAdd As System.Windows.Forms.Button
Friend WithEvents btnMErase As System.Windows.Forms.Button
Friend WithEvents btnMRecall As System.Windows.Forms.Button
Friend WithEvents btnSquareRt As System.Windows.Forms.Button
Friend WithEvents btnPercent As System.Windows.Forms.Button
Friend WithEvents btnCE As System.Windows.Forms.Button
Friend WithEvents btnNegative As System.Windows.Forms.Button
Friend WithEvents txtSign As System.Windows.Forms.TextBox
Friend WithEvents txtAnswer As System.Windows.Forms.TextBox
Friend WithEvents txtDisplay2 As System.Windows.Forms.TextBox
End Class
--------------------------------------------------------------------------------------------Code:
Public Class Form1


'Inherits System.Windows.Forms.Form


Dim Numbers() As Integer = New Integer(1) {total1, total2}
Dim total1 As Integer
Dim total2 As Integer
Dim sign As String
Dim total3 As Decimal
Dim read As Double


Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click


If txtDisplay.Text = "" Then
txtDisplay.Text = ""
Else
txtDisplay.Text = txtDisplay.Text & "0"
End If


End Sub


Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click


txtDisplay.Text = txtDisplay.Text & "1"


End Sub


Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click


txtDisplay.Text = txtDisplay.Text & "2"


End Sub


Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click


txtDisplay.Text = txtDisplay.Text & "3"


End Sub


Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click


txtDisplay.Text = txtDisplay.Text & "4"


End Sub


Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click


txtDisplay.Text = txtDisplay.Text & "5"


End Sub


Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click


txtDisplay.Text = txtDisplay.Text & "6"


End Sub


Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click


txtDisplay.Text = txtDisplay.Text & "7"


End Sub


Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click


txtDisplay.Text = txtDisplay.Text & "8"


End Sub


Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click


txtDisplay.Text = txtDisplay.Text & "9"


End Sub


Private Sub btnDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click


If txtDisplay.Text = "." Then
txtDisplay.Text = total3
Else
txtDisplay.Text = txtDisplay.Text & "."
End If


btnDot.Enabled = False


End Sub


Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click


total1 = txtDisplay.Text
sign = "+"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)



End Sub


Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click


total1 = txtDisplay.Text
sign = "-"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)


End Sub


Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click


total1 = txtDisplay.Text
sign = "*"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)


End Sub


Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click


total1 = txtDisplay.Text
sign = "/"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)


End Sub


Private Sub btnNegative_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNegative.Click


total1 = txtDisplay.Text
sign = "-"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)


End Sub


End Class

Hi Suley, Welcome to Daniweb.
1. Post your current code not with generated code.
2. Use code tags when you post code, its hard to see them. none will answer this thread caused your unable to use tags code.

"your if..else will looks like this in select...case

Private Sub ComboOperan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboOperan.SelectedIndexChanged
        Select Case ComboOperan.SelectedItem
            Case "+"
                MsgBox((Convert.ToInt32(txtNumber1.Text) + Convert.ToInt32(txtNumber2.Text)))
            Case "-"
                MsgBox((Convert.ToInt32(txtNumber1.Text) - Convert.ToInt32(txtNumber2.Text)))
            Case "*"
                MsgBox((Convert.ToInt32(txtNumber1.Text) * Convert.ToInt32(txtNumber2.Text)))
            Case "/"
                MsgBox((Convert.ToInt32(txtNumber1.Text) / Convert.ToInt32(txtNumber2.Text)))
        End Select
    End Sub

You can change Msgbox with your TextboxResult.Text...
OK. Hope This Helps.."

sorry, i didnt understand what you meant........
from the code you have posted in the screenshot above, it looks like you were trying to determine which type of calculation the user wanted to do and then used the two numbers to do that calculation (i.e. if the user clicks on the "+" button it will add the two numbers) but that is not the problem, i can determine which operation (+, -, /, *) the user clicks on and i can store a number in the first variable but i cannot store a number in the second variable......

i have 2 textboxes (txtDisplay, and txtDisplay2) to store the 2 different numbers and then another textbox (txtSign) which stores the value of the operator. I can store the first number from txtDisplay and I can store the operator from txtSign but the problem is that I cant store the second number from txtDisplay2........

if you know any way to make it easier (e.g. use one textbox for the whole thing, etc) or if you know that im missing something or just anything that can help i would be very grateful......

hope this makes the problem clearer......
thanks

sorry, i didnt understand what you meant........

what i means is not related with mycode, but your code in your previous post.
- Use Code tags to make your code more neat in sight
- then post your original code not generated codes by vb.net.

i have 2 textboxes (txtDisplay, and txtDisplay2) to store the 2 different numbers and then another textbox (txtSign) which stores the value of the operator. I can store the first number from txtDisplay and I can store the operator from txtSign but the problem is that I cant store the second number from txtDisplay2........

Why you can store second number??you can store in variable.

"

Why you can store second number??you can store in variable.

"

well the thing is that it doesnt matter if i use one textbox to store the first number, the sign and the second number or whether i use three different textboxes........

for some reason once my program has stored the first number (in a variable called "total1") and the sign (in a variable called "sign") i cant seem to come up with a way of storing the second number (as a variable called "total2")........

once i can do this, im sure i will be able to work out how to do the different calculations and manipulate both numbers in the ways i need to but since i cant store a number as the second variable (total2) i simply cant move on........ anyone got any solutions??

thanks.

what the problem with storing in variable???

total1 = textbox1.text
total2 = textbox2.text
sign = combobox1.SelectedItem
commented: he didn't understand what the problem is... +1

what the problem with storing in variable???

total1 = textbox1.text
total2 = textbox2.text
sign = combobox1.SelectedItem

well basically, when i try to store a number as the second variable it doesnt store a number.......

maybe if you take a look at my original code that i posted then you might be able to see something which could be causing the problem but im not experienced in VB.NET so maybe i have done something wrong without knowing it but any suggestions are very much appreciated.......

yeah, post a code more help.
i'll waiting your code.

yeah, post a code more help.
i'll waiting your code.

my code is below, can you please check it and see if you notice anything that is causing the problem and let me know. Thanks
---------------------------------------------------------------------------
Code:
Public Class Form1

'Inherits System.Windows.Forms.Form

Dim Numbers() As Integer = New Integer(1) {total1, total2}
Dim total1 As Integer
Dim total2 As Integer
Dim sign As String
Dim total3 As Decimal
Dim read As Double

Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click

If txtDisplay.Text = "" Then
txtDisplay.Text = ""
Else
txtDisplay.Text = txtDisplay.Text & "0"
End If

End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

txtDisplay.Text = txtDisplay.Text & "1"

End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

txtDisplay.Text = txtDisplay.Text & "2"

End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click

txtDisplay.Text = txtDisplay.Text & "3"

End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click

txtDisplay.Text = txtDisplay.Text & "4"

End Sub

Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click

txtDisplay.Text = txtDisplay.Text & "5"

End Sub

Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click

txtDisplay.Text = txtDisplay.Text & "6"

End Sub

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click

txtDisplay.Text = txtDisplay.Text & "7"

End Sub

Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click

txtDisplay.Text = txtDisplay.Text & "8"

End Sub

Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click

txtDisplay.Text = txtDisplay.Text & "9"

End Sub

Private Sub btnDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click

If txtDisplay.Text = "." Then
txtDisplay.Text = total3
Else
txtDisplay.Text = txtDisplay.Text & "."
End If

btnDot.Enabled = False

End Sub

Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click

total1 = txtDisplay.Text
sign = "+"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)


End Sub

Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click

total1 = txtDisplay.Text
sign = "-"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)

End Sub

Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click

total1 = txtDisplay.Text
sign = "*"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)

End Sub

Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click

total1 = txtDisplay.Text
sign = "/"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)

End Sub

Private Sub btnNegative_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNegative.Click

total1 = txtDisplay.Text
sign = "-"
txtSign.Text = sign
MsgBox(total1)
MsgBox(total2)

End Sub

End Class

hey is ur code correct,coz i hav been given an asignment to create a simple calc, i tried hard bt my code dosen't wrk can u help me out plz.......

well, sorry for taking so long to reply, ive been quite busy for a while now but with regards to the calculator assignment.......

i have some code which worked almost to perfection when i had to hand mine in (for an assignment).....

unfortunately my trial period has run out but i will post the code on here within the next couple of days.......

hope it helps......

thanks,
see you later and good luck! :)

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.