Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,543 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,540 people online right now. Registration is fast and FREE... Join Now!




vb 2005 express calculator

 
Reply to this topicStart new topic

vb 2005 express calculator

jmess322
18 Nov, 2007 - 08:49 AM
Post #1

New D.I.C Head
*

Joined: 18 Nov, 2007
Posts: 2


My Contributions
Hi people, new to this site, and the vb language. I have been working on a four function calculator and I have not gotten it to work out the calculations. I can't get the right code for the equals button, but even after that I don't know the code for each individual arithmetic operator (+,-,*,/). So far I have just worked on the plus Button. Here is my code, any help would be appreciated. I omitted buttons 1-9 (same as 0) and the operations that I haven't worked on yet.

CODE


Public Class Form1

    Inherits System.Windows.Forms.Form

    Dim total1 As Integer
    Dim total2 As Integer
    

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

        txtDisplay.Text = txtDisplay.Text & btn0.Text

    End Sub

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

        total1 = txtDisplay.Text   'Textbox entry stored in variable total1
        total1 = total1 + Val(txtDisplay.Text)   'Variable total1 contains number in total1 plus the number in the textbox
        txtDisplay.Clear()

    End Sub

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

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



    End Sub

    'Clear Button
    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click

        txtDisplay.Clear()

    End Sub
End Class


User is offlineProfile CardPM
+Quote Post

oXiDe
RE: Vb 2005 Express Calculator
18 Nov, 2007 - 09:03 AM
Post #2

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 37



Thanked: 1 times
My Contributions
hey i made one of those yesterday
your's seems alot more complicated, but for the addition thing on mine i did:

CODE
Option Explicit
    Dim first As Double
    Dim second As Double
    Dim Outputs As Double

Private Sub cmdAdder_Click()

    first = txtfirst.Text
    second = txtsecond.Text
    Outputs = first + second
    txtOutput.Text = Outputs
    
End Sub


and if i were u i'd use Double instead of Integer since Double goes way farther bfor overflow :l
User is offlineProfile CardPM
+Quote Post

jmess322
RE: Vb 2005 Express Calculator
18 Nov, 2007 - 10:03 AM
Post #3

New D.I.C Head
*

Joined: 18 Nov, 2007
Posts: 2


My Contributions
What do you do with the equals button? It would be nice to have the addition button show intermediate results (i.e. 3 + 5 + (click shows "8") 4 + (click shows "12) ), but I can't see what to do in the equals button code, considering there are buttons of multiple arithmetic operations.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Vb 2005 Express Calculator
18 Nov, 2007 - 10:12 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
First, Visual Basic 2005 Express Edition is VB.Net so this belongs in that forum (I am moving it for you smile.gif ). Also, I have written a tutorial on Creating a basic calculator in VB.Net so you may want to look through that smile.gif
User is online!Profile CardPM
+Quote Post

Zerro
RE: Vb 2005 Express Calculator
18 Nov, 2007 - 02:20 PM
Post #5

New D.I.C Head
*

Joined: 16 Nov, 2007
Posts: 4


My Contributions
Alright, I am going to start you off with an algorithm. ok
Say you have 9 buttons, one for each number. You also have a txtbox(just one. When you click a number you can do txtbox = txtbox & num, but a better algorithm is txtbox = txtbox * 10 + num.

when you click the math opperator button, you need to store txtbox to a var. and have a var set to the math opperator.
on equals
run through if's or a select case to fine the right math. Then do your operation.

Hope that helps.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 09:26PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month