• (3 Pages)
  • +
  • 1
  • 2
  • 3

Basic Calculator in VB.Net Rate Topic: **--- 3 Votes

#31 Guest_due*


Reputation:

Posted 20 July 2010 - 09:55 AM

hi i am designing my calculator but i want the first number to remain after the operator is selected and removed when another number is selected.

for eg 3 + 2 = 5, i want the 3 to remain on the screen until the 5 is selected can anyone help me with this
Was This Post Helpful? 0

#32 Guest_dude*


Reputation:

Posted 20 July 2010 - 09:56 AM

hi i am designing my calculator but i want the first number to remain after the operator is selected and removed when another number is selected.

for eg 3 + 2 = 5, i want the 3 to remain on the screen until the 5 is selected can anyone help me with this
Was This Post Helpful? 0

#33 Guest_$heikh*


Reputation:

Posted 24 August 2010 - 01:22 AM

hi sir
i m new in vb.net.
i read out this tutorial but i m unable to downlad the rar file completly.there is some error in downloading only 108 kb data is downloaded & rest it not downloaded.

so kindly solve this problem as soon as possible.
Was This Post Helpful? 0

#34 skyvergil83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-December 10

Posted 08 December 2010 - 09:20 PM

Hi PsychoCoder, i'm currently building a calculator application in vb.net using your calculator as my reference.
i have a question to ask you, have you ever try to add a few radiobutton to make number base conversion?

Eg: From decimal base 10 number (30), when i click a radio button, it will convert the number to binary base 2 number(11110).

Currently i'm still trying to find a way solve this problem, because i could not convert the number directly from the textbox, it didn't get any value from the textbox, but if i do some operation, eg: 29 + 1 and get 30, when i press the radio button, it does the conversion without any problem or error, which means it gets the value from the variable, but it cannot get the value from the textbox directly.

below is my example code in my radio button:

Private Sub rdbbin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbbin.CheckedChanged
Dim x As Integer
Dim counter As Integer = 0
Dim val2 As Double = nom1
Dim y As Integer

While counter < val2
x = val2 Mod 2
ListBox1.Items.Add(x)
val2 = val2 \ 2
'TextBox1.Text = TextBox1.Text & x
End While

For y = ListBox1.Items.Count - 1 To 0 Step -1
TextBox1.Text = TextBox1.Text & ListBox1.Items(y)
Next y


End Sub


i use the methods that you provide to build this calculator, including the inputstatus flag too. In these case, my nom1 variable is the alias of your valHolder1 variable. I hope you can help me on this because this is my 1st project as and new learner in vb.net.

Your kindness help will be much appreciated.

thank you

regards

Gan
Was This Post Helpful? 0
  • +
  • -

#35 Yannis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-January 11

Posted 30 January 2011 - 09:40 AM

Hi there - my first post :)

I'm a beginner but I found an error within the decimal button.

It's this:

hasDecimal = True


hasDecimal remains true if you click on the decimal button again! That way it will cease to work. So at the beginning we must complement:

If inputStatus Then
hasDecimal = False


Thank you very much for the tutorial - I'm still working on it.

Yannis.

EDIT: won't work that way because if we click again on the decimal button the decimal will show twice. So we need to make sure that the first time we make use of the decimal button it will block it but the second time (I mean when we type in a new number) it still works.

This post has been edited by Yannis: 30 January 2011 - 09:46 AM

Was This Post Helpful? 0
  • +
  • -

#36 Yannis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-January 11

Posted 30 January 2011 - 10:03 AM

Ok I found the solution to my problem above with the decimal button.

We just have to add

hasDecimal = False


to the all buttons exept the numbers 0 to 9 or the decimal button itself. I'm not sure about the +/- button though.

This way the decimal button can be used as many times as possible
Was This Post Helpful? 0
  • +
  • -

#37 JayGee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-March 11

Posted 16 March 2011 - 05:24 PM

Hello: I've been working with your Calculator Code to build one in a VB course. But, I had to have a CLASS for the calculations. Everything seems to work up to the point of hitting the EQUAL Key and it just stops there. I wondered if you might take a look at my code below and see if you can see anything I might have done wrong. The code has been separated between the CLASS and the MAIN FORM Calculator. I've been through this several times and I just do not see where the problem is. No errors are reported and I've stepped through debugging several times and this just hangs at the EQUAL input.


‘  Calculate Totals CLASS
    ' sets Property value to be used in Main Form
    Public Property UserInput() As String
        Get
            Return _txtInput
        End Get
        Set(ByVal value As String)
            _txtInput = value.Substring(valHolder1)
        End Set
    End Property

‘  Main Form Calculator
    Private Sub btnEqual_Click(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) _
                               Handles btnEqual.Click
        ' Make sure something is in the input box and the temp value isn't "0"
        If txtInput.Text.Length <> 0 AndAlso valHolder1 <> 0 Then
            ' call the CalcTotals method
            lblUserInput = CalcTotals
            ' clear the calcFunction value
            calcFunc = String.Empty
            ' toggle the decimal flag
            hasDecimal = False
        End If
    End Sub



Was This Post Helpful? 0
  • +
  • -

#38 Arkyz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-March 12

Posted 22 March 2012 - 03:44 AM

Thanks

this really helped me make a calculator for my family to use
Was This Post Helpful? 0
  • +
  • -

#39 suman.samanta1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-September 12

Posted 05 September 2012 - 06:34 AM

Public Class Form1
Dim mfirst As Double
Dim msecond As Double
Dim manswer As Double
Dim mbutton As Double
Dim Signstate As Boolean
Private Sub cmd0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd0.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 0
End Sub

Private Sub cmd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd1.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 1

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub cmd2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd2.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 2
End Sub

Private Sub cmd3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd3.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 3

End Sub

Private Sub cmd4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd4.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 4

End Sub

Private Sub cmd5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd5.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 5

End Sub

Private Sub cmd6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd6.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 6

End Sub

Private Sub cmd7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd7.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 7

End Sub

Private Sub cmd8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd8.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 8

End Sub

Private Sub cmd9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd9.Click
Me.TextBox1.Text = (Val(Me.TextBox1.Text) * 10) + 9

End Sub

Private Sub cmd_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_add.Click
mbutton = 1
mfirst = Val(Me.TextBox1.Text)
Me.TextBox1.Text = ""

End Sub

Private Sub cmd_sub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_sub.Click
mbutton = 2
mfirst = Val(Me.TextBox1.Text)
Me.TextBox1.Text = ""
End Sub

Private Sub cmd_mul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_mul.Click
mbutton = 3
mfirst = Val(Me.TextBox1.Text)
Me.TextBox1.Text = ""
End Sub

Private Sub cmd_div_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_div.Click
mbutton = 4
mfirst = Val(Me.TextBox1.Text)
Me.TextBox1.Text = ""
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
msecond = Val(Me.TextBox1.Text)
Select Case mbutton

Case Is = 1
manswer = mfirst + msecond
Case Is = 2
manswer = mfirst - msecond
Case Is = 3
manswer = mfirst * msecond
Case Is = 4
manswer = mfirst / msecond
Case Is = 5
manswer = System.Math.Pow(mfirst, msecond)
End Select
Me.TextBox1.Text = manswer
End Sub

Private Sub cmd_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_exit.Click
'exit(Me)
End Sub

Private Sub cmd_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_cancel.Click
Me.TextBox1.Text = ""

End Sub

Private Sub cmddot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddot.Click
Me.TextBox1.Text = Me.TextBox1.Text + "."

End Sub

Private Sub Btn_pow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_pow.Click
mbutton = 5
mfirst = Val(Me.TextBox1.Text)
Me.TextBox1.Text = ""

End Sub
End Class
Was This Post Helpful? 0
  • +
  • -

#40 Visual Basic programer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-December 12

Posted 28 December 2012 - 02:38 PM

Hey,
this is wery good calculator but it has many codes and I made my own calculator and it has less codes:
http://www.mediafire...8jyd1jb81hxpdtm
hope you guys enjoy my too
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3