10 Replies - 90006 Views - Last Post: 07 December 2010 - 01:57 PM Rate Topic: -----

#1 mdk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-March 06

VB.net Calculator

Posted 20 March 2006 - 02:47 PM

:pirate: Can anyone give me some tips how to build a simple calculator in VB; i got the interface with buttons and text box alredy and i figured out how to put more then one number using buttons alredy(Disp.Text = Disp.Text & 1) :), Looking at the windows calc, how do you store the number u just entered into a text box and alowe user to enter another to performe calculations, what code should i use for equal button and etc. any feadback,instr. hints, code, will be appreciated...Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: VB.net Calculator

#2 Xenon  Icon User is offline

  • Connection failed
  • member icon

Reputation: 8
  • View blog
  • Posts: 1,595
  • Joined: 12-September 05

Re: VB.net Calculator

Posted 20 March 2006 - 02:56 PM

ok since what your trying to do is a very common project ill suggest you look at this Vb.net Calculator Project , its got nice explanation

This post has been edited by Xenon: 20 March 2006 - 02:58 PM

Was This Post Helpful? 0
  • +
  • -

#3 mdk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-March 06

Re: VB.net Calculator

Posted 20 March 2006 - 03:33 PM

thanks :D
Was This Post Helpful? 0
  • +
  • -

#4 vatyk  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 08-September 07

Re: VB.net Calculator

Posted 08 September 2007 - 09:41 AM

Hi! I need to build a calculator, but I need to insert the numbers in a text box using my keyboard. Can anyoane help me with this? I don't know how to make the text box accept only numbers and how to work with the numbers I assign (from keyboard). Thank you.
Was This Post Helpful? 1

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: VB.net Calculator

Posted 09 September 2007 - 06:37 PM

I have written a tutorial on creating a calculator in VB.Net

Basic Calculator in VB.Net
Was This Post Helpful? 0
  • +
  • -

#6 seadannie  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 26-July 08

Re: VB.net Calculator

Posted 26 July 2008 - 02:44 AM

View PostXenon, on 20 Mar, 2006 - 02:56 PM, said:

ok since what your trying to do is a very common project ill suggest you look at this Vb.net Calculator Project , its got nice explanation

I went to this site but I'm stuck on the equals button exercise. There is a third line of code that resets the variable total1 to zero and I'm having trouble thinking of what it is.

Here is my code:

Public Class Form1

	Dim total1 As Integer
	Dim total2 As Integer

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

		txtDisplay.Text = txtDisplay.Text & btnthree.Text

	End Sub

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

	End Sub

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

		txtDisplay.Text = txtDisplay.Text & btnseven.Text

	End Sub

	Private Sub btnzero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnzero.Click

		txtDisplay.Text = txtDisplay.Text & btnzero.Text


	End Sub

	Private Sub btnone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnone.Click

		txtDisplay.Text = txtDisplay.Text & btnone.Text

	End Sub

	Private Sub btntwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntwo.Click

		txtDisplay.Text = txtDisplay.Text & btntwo.Text

	End Sub

	Private Sub btnfour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfour.Click

		txtDisplay.Text = txtDisplay.Text & btnfour.Text

	End Sub

	Private Sub btnfive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfive.Click

		txtDisplay.Text = txtDisplay.Text & btnfive.Text

	End Sub

	Private Sub btnsix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsix.Click

		txtDisplay.Text = txtDisplay.Text & btnsix.Text

	End Sub

	Private Sub btneight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneight.Click
		txtDisplay.Text = txtDisplay.Text & btneight.Text

	End Sub

	Private Sub btnnine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnine.Click
		txtDisplay.Text = txtDisplay.Text & btnnine.Text

	End Sub

	Private Sub cmdPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlus.Click

		total1 = total1 + Val(txtDisplay.Text)

		txtDisplay.Clear()

	End Sub

	Private Sub cmdEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEquals.Click

		total2 = total1 + Val(txtDisplay.Text)
		txtDisplay.Text = total2



End Sub
End Class

I think I figured it out. Here is what I did.

total1 = btnzero.Text


I can't believe it took me a whole day to figure that out. :w00t: :blush:

This post has been edited by seadannie: 26 July 2008 - 10:15 PM

Was This Post Helpful? 1

#7 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: VB.net Calculator

Posted 01 December 2009 - 05:11 PM

View Postvatyk, on 8 Sep, 2007 - 08:41 AM, said:

Hi! I need to build a calculator, but I need to insert the numbers in a text box using my keyboard. Can anyoane help me with this? I don't know how to make the text box accept only numbers and how to work with the numbers I assign (from keyboard). Thank you.

Just add textbox to your form and type stuff into it that simple
Was This Post Helpful? 0
  • +
  • -

#8 some_kid  Icon User is offline

  • New D.I.C Head

Reputation: 10
  • View blog
  • Posts: 43
  • Joined: 26-May 09

Re: VB.net Calculator

Posted 03 December 2009 - 09:29 PM

Why has this thread been revived every year since 2006?


If any more questions come up check PsychoCoders tutorial for a basic calculator.
If you need a more advance calculator check http://www.vbprogram...dCalculator.htm




Remember people when 2010 comes post in here
Was This Post Helpful? 0
  • +
  • -

#9 Guest_smart_alec*


Reputation:

Re: VB.net Calculator

Posted 20 February 2010 - 08:57 PM

Ok, it's 2010... Somebody had to... :)

View Postsome_kid, on 03 December 2009 - 08:29 PM, said:

Why has this thread been revived every year since 2006?


If any more questions come up check PsychoCoders tutorial for a basic calculator.
If you need a more advance calculator check http://www.vbprogram...dCalculator.htm




Remember people when 2010 comes post in here

Was This Post Helpful? 0

#10 Guest_spike*


Reputation:

Re: VB.net Calculator

Posted 26 March 2010 - 01:10 AM

seems like I cant make this equal button to work properly...doesn't even add the 1st value to the current txtdisplay.text... nid ur help pls!


Private Sub btnEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqual.Click

'Dim total2 As Integer

total2 = total1 + Val(txtDisplay.Text)
txtDisplay.Text = total2

MsgBox(total2)

End Sub
End Class
Was This Post Helpful? 0

#11 Guest_omar Abdo*


Reputation:

Re: VB.net Calculator

Posted 07 December 2010 - 01:57 PM

View Postspike, on 26 March 2010 - 12:10 AM, said:

seems like I cant make this equal button to work properly...doesn't even add the 1st value to the current txtdisplay.text... nid ur help pls!


Private Sub btnEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqual.Click

'Dim total2 As Integer

total2 = total1 + Val(txtDisplay.Text)
txtDisplay.Text = total2

MsgBox(total2)

End Sub
End Class


You have to define total1 and total2 at the top of your form
01 Public Class Form1
02
03 Dim total1 As Integer
04 Dim total2 As Integer

DON'T DEFINE THEM AGAIN AT EACH BUTTON
I HOPE THAT'S HELPFUL
Was This Post Helpful? 0

Page 1 of 1