27099 total geeks with 3528 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
MaxMouse
It's Friday... That's good enough for me!
CodeX
non stop lolz here but thats soon to end thanks to uni, surely the rest of the world is going good?
stabat
how things are going guys? Here... boring...
CodeX
I must be going wrong on the password lengths then, as long as it was done on ECB
MaxMouse
lol... the key is in hex (MD5: of the string "doit" without the "'s) and is in lower case. Maybe i should have submitted this as a challenge!

Donate
Donate and help us fund new challenges
Donate!
Due Date: Oct 31
October Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
Facebook says
vendor secrets
forced it to
homebrew switches
Free
government-penned
crypto can swipe
identities
So long, thanks for
all the ...er, FISH
BRIGHTER than
boffins thought
Multi Jet Fusion is
HP"s promised 3D
printer, not crazy
"leccy invention
Google heads out
the back with
rifle, puts down
POODLE
FIFTEEN whole
dollars on offer
for cranky Pentium
4 buyers
Microsoft gets
storage QoS and
software-defined
storage religion
Plasma-spaffing
boffins plan
spaceships driven
by FRIKKIN" LASERS
Desktop Linux users
beware: the boss
thinks you need to
be managed
Google"s Mr.
Roboto, Andy Rubin,
to bid
sayonara
Slashdot
Swedish Regulator
Orders Last
"Hold-Out" ISP To
Retain Customer
Data
Mark Zuckerberg And
John Doerr Donate
$1M To Expand The
Hour Of Code
Campaign
Denmark Plans To Be
Coal-Free In 10
Years
France
Investigating
Mysterious Drone
Activity Over 7
Nuclear Power Plant
Sites
Researchers Claim
Metal "Patch" Found
On Pacific Island
Is From Amelia
Earhart
New Study Shows
Three Abrupt Pulses
of CO2 During Last
Deglaciation
Google To Disable
Fallback To SSL 3.0
In Chrome 39 and
Remove In Chrome 40
Charity Promotes
Covert Surveillance
App For Suicide
Prevention
Vulnerabilities
Found (and Sought)
In More
Command-Line Tools
Getting "Showdown"
To 90 FPS In UE4 On
Oculus Rift
Article viewer

Simple Calculator in VB



Written by:dimport
Published by:Nightscript
Published on:2003-06-21 07:19:46
Topic:Visual Basic
Search OSI about Visual Basic.More articles by dimport.
 viewed 569152 times send this article printer friendly

Digg this!
    Rate this article :
This tutorial will demonstrate how to code up a simple calculator, note this calculator will manipulate two numbers and will not account for error catching in any great degree.



Think your a GEEK? Prove it on the Geek Challenges





This tutorial will teach you:-

-Simple Arrays

-Manipulating numbers

-Implementing summing

Let's begin. Firstly we need to create the interface. So you'll need to crank
up ole VB. Put a text box up the top, clear it and give it a decent name like
txtDisplay, now we need to create the numbers, these will be command buttons
and must be an array, the easiest way to do this is to just create one button,
copy and paste it, and when the system asks do you want to create a control
array, you click yes! But what is and array? Well simply put it is a collection
of related variable that share the same type.

Do this for all the numbers 0
through 9, just like on Windows own calculator. Now you need to do the same
for the methods of calculation, the - + * etc. Now you should have something
that resembles a calculator. Of course these aren't the only buttons you'll
need dont forget the equals sign and of course some form of clear, I use C just
like Windows' own calculator. And now onto some coding.

We are going to need three variables, one for the first number of type double
(to hold large numbers.) one for the second number, and of course one for the
sign, or type of calculation we are doing. This is how I have declared them.

 
Dim first As Double
   Dim second As Double
   Dim sign As String
 


Not to bad so far, let's get those nasty arrays out of the way.

 
Private Sub Command1_Click(Index As Integer)
        If txtDisplay.Text = "" Then
             txtDisplay.Text
  = Command1(Index).Caption
        Else
             txtDisplay.Text
  = txtDisplay.Text & Command1(Index).Caption
        End If
   End Sub


This is the array, what this does is makes the content of the display screen
equal to the caption that has been clicked. In other words if you click the
button with 1 on it the number one will go to the display text box. The same
applies for the following array sub.

Private Sub Command2_Click(Index As Integer)
        first = txtDisplay.Text
        txtDisplay.Text = ""
        sign = Command2(Index).Caption
   End Sub


Now what this does is assign the value of the display to the first variable,
this makes it nice and easy to manipulate two numbers, it's my tip of the day,
next it clears the content of the display box and then assigns the sign to the
sign variable. And now for a minimal effort at keeping the user from crashing
it.

Private Sub Form_Load()
   txtDisplay.Enabled = False
   txtDisplay.MaxLength = 10
   End Sub


On form load set max length of the text box to 10 and dont let anything get
stuck in the text box by any other method then hitting the command buttons.
Now lets see our hard work pay off by adding the calculation sub.

Private Sub cmdEq_Click()
        second = txtDisplay.Text
        If sign = "-" Then
             txtDisplay.Text
  = first - second
        ElseIf sign = "+" Then
             txtDisplay.Text
  = first + second
        ElseIf sign = "*" Then
             txtDisplay.Text
  = first * second
        ElseIf sign = "/" Then
             txtDisplay.Text
  = first / second
        End If
   End Sub


Firstly the sub assigns whats in the display to the variable named second.
It then works out what calculation should be done by finding the current value
for the sign variable, so if the variable is / then it will devide the first
number by the second. And that in essence is the calculator, not to bad I thought,
and easy enough for you to build on and create a much more complex one. There
are a few mor subs we should explore but don't deserve any special attention.

Private Sub cmdDot_Click()
        If InStr(txtDisplay.Text, ".") = 0 Then
             txtDisplay.Text = txtDisplay.Text & "."
        End If
   End Sub


This tests if there is a . in the box before adding one.

Private Sub cmdClear_Click()
       txtDisplay.Text = "0"
   End Sub


Resets the display box.


This is all there is to writing a simple calculator program in VB it's barely
a page worth of actual code.

What you should have learned :-
-Array use
-Simple error cactching
-Using numbers in Visual Basic with mathematical calculations



This article was originally written by Sliptop

Did you like this article? There are hundreds more.

Comments:
Sarkie
2005-06-17 10:02:18
Right all seems to fine with this, aslong as you understand how to set up the gui so you are creating an array of command buttons and putting 0-9 on them, and some others for *,/,-,+ then all is ok, just to mention even though with this calculator it is not possible first = txtDisplay.Text i would have changed to first = Val(txtDisplay.Text), just out of practice, anyway. If you still need help I'll provide some.

Sarkie
FaTaL_PrIdE
2005-06-17 14:54:27
Ah, blatant plagiarism... where would we be without it?
Domuk
2005-06-22 18:26:43
http://www.osix.net/modules/folder/index.php?tid=7504&action=vf
Anonymous
2006-02-02 13:29:35
Well, my codes for the cal go different and i am stuck up with, its not taking the second digit into display. Help me out.......
anilg
2006-02-02 16:50:07
Try F5ing the code..a nd post the lines that seem to be giving errors.
Anonymous
2006-04-13 00:29:28
if you not getting anything to display check the index, it should be blank for Clear,Equal and dot. Also 0-9 should all be Command1 but they should have a ranging index that also goes from 0-9. The same goes for (+)(-)(/)(*) They should all be named Command2 and have a ranging index of 0-3. Things will mess up if somthing insn't an array and the index is somthing other then blank. I Hope this clear things up for anyone that has or will look at this post. because the Author failed to throughly explain such things.
MaxMouse
2006-08-25 21:38:07
Whats funny about that fellow is it seems everyone younger than 18-19 is using that type of language, examiners have even had to go on several courses to understand the "New-age language" as it is now submissible in exams.

Personally i hate such abbreviations and put it down to sheer lazyness, ok on a mobile-phone where you have limited space i guess its ok, but on paper/e-mails whats the point? i proved this to my sister not long back i typed normal english she typed her txt-slang and i still managed to finish before her, it doesn't look cool and its not easier.

Granted, i make spelling mistakes lol

Ref:
http://www.bbc.co.uk/voices/yourvoice/language_rules1.shtml
http://www.bbc.co.uk/wales/northeast/sites/your_shout/pages/txt.shtml
http://scotlandonsunday.scotsman.com/index.cfm?id=350682003
Anonymous
2006-09-10 10:57:46
Well I'm fifteen and though English is not my mother tongue, I greatly digress with such way of using the English language. Not everyone speaks that way; perhaps only those who are stupid enough to think that they're cool if they could speak that way.

Anyway, I've had the bad luck of having to create a VB Calculator. Thanks for the article.

(The previous comments actually made me laugh.)
Anonymous
2006-10-19 11:57:30
Thanks very much for this tutorial but theres just one problem. Im using Visual Basic 2003 and the thing is, after I create and copy all the buttons, No message box appears asking me to create an array? Whats the solution to this? Or is that feature not supported in VB 2003. What other way is there. Thanks
Anonymous
2006-10-19 17:30:08
This tutorial really helped me a lot.....i've done a simple calculator by my means, and toke some ideas from this...

but i've used 4 "dims" :p in my calculator..... another one for the result ;) more simple for me....
Anonymous
2006-10-19 20:25:40
Anyone? How to make an array manually? Again, I copied the buttons but still no response. And what names did you asign to them?
Anonymous
2006-12-04 20:14:57
sub btnOne_Click(ByVal whatever, and ever, not important)

txtBox.text = appendtext(cstr("1")

'um that skips alot of stuff you just did...
'just convert text later
'oh and i think this only works for 05
Anonymous
2007-01-11 11:59:30
can any1 help me with inserting a percentage button on visual basic working in the followin way??

enter a number
press the * button
enter the 'percent' of number
press the % button
Anonymous
2007-01-25 13:44:20
I'm not pretty sure how to do this, but why not add:

If keycode = vbKeyA then

End If

It should be used to make it possible to press the +,-,* or / to put it out in the textfield.
I think the ASCII numbers for the keys must be used. Cause it didn't work with + for me to end a program....
Anonymous
2007-02-15 09:03:08
To the person whoz equal is not working... Did you include Val at the front of your integer values?? eg. Sum= Val(Numkey1)+Val(Numkey2)

This calls the integer values of the text field to be added and not the string.
learner-hacker
2007-05-17 07:37:21
Great work. It took a fair bit of studying for a beginer in VB such as myself, but I finally realised what I was doing wrong and it's now exactly what I hoped for! :D thank you for giving me the base to my calculator.
Now I have much work to do in adding to it :) Thanks again!
Anonymous
2007-08-25 09:17:30
this is not a very good example of a calculator, for one you can only operate on two numbers, secondly there is no error catching for when someone was to press an operator button twice... and there should be better description on what command button 1 and command button 2 actually refer too. designing the program is just as important as coding the program! please keep this in mind, especially when dealing with VB
Anonymous
2007-08-25 09:21:25
i dont see the point of the txtDisplay.MaxLength = 10 , try entering in 999999999 and then add with any number, see what happens.....
Anonymous
2007-10-09 11:51:19
Perhaps you should tell which version of VB you are using, it would make it easier to know if it definetely will work for the one you have, or if perhaps I have an other version, because it doesnt seem to work when I type your coding in. Only get error every fking where.
Anonymous
2007-11-22 18:57:11
Private Sub btnSquareRoot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSquareRoot.Click
If txtDisplay.Text.Length <> 0 Then
tmpValue = CDbl(txtDisplay.Text)
tmpValue = System.Math.Sqrt(tmpValue)
txtDisplay.Text = CStr(tmpValue)
End If
End Sub

thats for SquareRoot... but i need Percentage =.=
Anonymous
2007-12-26 01:05:54
code for decimal and +/-
Anonymous
2008-01-18 11:07:59
ur code is not proper.
aftre clicking on the add button,it will show addition of second no only,and the first one is ignored.
i.e. if we click on 1+2,it will show 4 i.e. 2+2
kindly give the reply within 10 minutes.
Anonymous
2008-02-13 11:21:30
I would like to ask whether anyone knows visual basic6.0. If you do could you email me a calculator code with on vb6.0 . Only on the simply operands like +'-'* and /. PLEASE send me one .I have failed to make mine run 3times in a row now.
Anonymous
2008-04-10 09:07:12
i am a begginer in vb and it is difficult to me to understand the codes.. vb is a gui but when i started to generate the codes, it is very tricky and i dont know where to put the codes... it has a churveness of private and piblic! i cant understand... any one can help me coz my supervisor told me that i should be familiarize with vb but unfortunately we did not discuss that language in our school..
anyone can help me plsss..
im looking forward for the person who have a kind hearted to help me!!
kindly email me at flores.cynthia.29@gmail.com
im starting reading and browsing the net about vb tutorial etc... thanks a lot and have a nice day ahead to all of you...
mmmmmmwwwwwwaaaaaaaaaahhhhhhhhhhh!!!!!!!
Anonymous
2008-05-04 06:56:13
Thanks alot man! that was really Helpfull in our Collage Project!!! I really appreciate Your Help!!!!!!
Thanks a bunch!!
Anonymous
2008-05-14 15:02:46
if it still doesn't work then try pressing F6 at the same time as Ctrl-HUMP. That will make it work. if HUM P does not work try Atl-balls
Anonymous
2008-07-24 03:16:15
thanks for the creator codes in java thank3X
Anonymous
2008-08-02 18:00:24
i want to create a calculater in VB how to implemente.plese help me.asif
Anonymous
2008-08-11 05:41:30
does anyone have a code for the percent button
Anonymous
2008-08-20 14:09:20
i dnt know how to work with the array thing can any1 help? i use vb6
Anonymous
2008-08-22 02:21:59
when i calculating with two numbers it give me a error message tat "argument not optional" and the "second ="(in the 'Private sub cmdEq_click()') is selected.what is the problem.....
Anonymous
2008-09-09 11:29:19
nt a proper code n cmpletely difficlt 2 follow
Anonymous
2008-09-12 17:31:40
jus one thing man i have copied the entire thing made boxes as u said an even done that array thing though i don't know wha it is an still it doesn't display ny result
Anonymous
2008-09-16 21:28:07
These comments make me laugh. If you are having trouble, why not ask on a forum or somewhere where somebody will actually reply?
Try looking back over the code for obvious mistakes kids.
Anonymous
2008-09-19 11:49:06
thanks for sucha a good article. I followed all the code the only thing I didn't undrestan was "command1 and command2". command1(index) and command2(index). Do I have to 'dim' them or ... could someone please answer, I will greatly appreciate
Anonymous
2008-10-07 19:00:44
Public Class Form1
Dim s = 0, a As Integer
Dim op As String
Dim b As String
Dim c As String




Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = 1
TextBox1.Text = "1"
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
a = 2
TextBox1.Text = "2"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
a = 3
TextBox1.Text = "3"
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
a = 4
TextBox1.Text = "4"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
a = 5
TextBox1.Text = "5"
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
a = 6
TextBox1.Text = "6"
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
a = 7
TextBox1.Text = "7"
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
a = 8
TextBox1.Text = "8"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
a = 9
TextBox1.Text = "9"
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
a = 0
TextBox1.Text = "0"
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
s = Integer.Parse(TextBox1.Text)
op = "+"
TextBox1.Text = ""


End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
s = 0
a = 0
TextBox1.Text = a.ToString()
End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
s = Integer.Parse(TextBox1.Text)
op = "-"
TextBox1.Text = ""

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If op = "+" Then
s = s + Integer.Parse(TextBox1.Text)
End If
If op = "-" Then
s = s - Integer.Parse(TextBox1.Text)
End If
If b = "*" Then
s = s * Integer.Parse(TextBox1.Text)
End If
TextBox1.Text = "0"
TextBox1.Text = s.ToString()
s = 0
End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click

s = Integer.Parse(TextBox1.Text)

b = "*"
End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
s = Integer.Parse(TextBox1.Text)
c = "/"
TextBox1.Text = ""
End Sub
End Class
Anonymous
2008-10-11 08:38:33
nice project
Anonymous
2008-10-21 06:11:45
tnx its helps me a lot i successfully run my simple calculator....

Computer innovation center of tagum incorporated student
cute_jhee
2008-10-21 06:22:27
thank you dimport..godblesssssss
CodeX
2008-11-08 00:48:03
if you are even were mildly capable programmer then you would be able to figure that out yourself, anywho, for the sake of stating the obvious:
ElseIf sign = "%" Then
             txtDisplay.Text
  = first % second

if you cant figure out where that goes then I'd recommend jumping of the highest structure you can find as many times as possible, but you may as well do that anyway just for fun :)
CodeX
2008-11-08 17:57:19
Might have been a bit harsh/non-constructive, if you feel the need to ask something so basic its apparent that you don't really know what your doing, even just looking through the code its intuitive as to what the modulo(%)(or modulus if your American) part should be even with minimal knowledge of programming (its not even far from English), so next time you feel like asking a question you should put some effort in: look up what you don't know on google (i.e. VB for beginners) and then try to solve the problem yourself, that way you get less harsh comments and you'll actually better yourself!
Anonymous
2008-12-01 09:55:19
is the equal sign button included in the command 2 array>?
Anonymous
2008-12-02 04:49:05
I would like to ask whether anyone knows visual basic6.0. If you do could you email me a calculator code with on vb6.0 . . PLEASE send me one .this is my @ add.<narshaxx09@yahoo.com>
narshaxx
2008-12-02 05:23:03
hey...thanks u for giving me nice codes in making a calculator.......

keep the good work master....<!>
Anonymous
2008-12-04 11:23:58
I need proper code for creating calcultor in vb 6.0
u given code doesnot eixt
Anonymous
2008-12-04 14:57:05
Hey, im making a calculator, and i have all these signs: / * - + , and they are working. But to get a higher mark i need to add extra buttons.. how do i do? and how do i make decimals ?
Anonymous
2009-01-04 14:34:01
i want scintific calculator program
SteSweeney
2009-01-07 18:36:56
Hey guy listen
If i Had a bucket and dumped it into this bucket it make a variable. THERE ARE TWO TYPES OF BUCKETS
SAJChurchey
2009-01-08 18:35:26
Please keep comments on topic and constructive. If you have nothing constructive to add . . . leave.
Anonymous
2009-01-15 06:22:29
good for student
Anonymous
2009-01-17 18:23:02
hello eveyone!
do someone know where can i find a calculator code that when u insert a value to the textbox and press on the operator (+,- etc) the number remain on the textbox and just after you begin to insert the second value the new calue remove the old one and display on the txtbox.

Please help me. thank's a lot =)
Anonymous
2009-01-31 06:49:21
thanks for help me on the calcular program i expect more on the vb.net
thank you
Anonymous
2009-02-16 13:28:38
i need a vb.net code for calculating more than 2 digit . the above accepts only 1 digit numbers plz........ i need it for my ug bsc project......plz.....
Anonymous
2009-02-26 17:43:31
i tried to use this in my class and it was to dang hard to understand it lol
Anonymous
2009-03-04 14:13:51
the code is somewhat not right????
Anonymous
2009-03-15 08:08:55
i would like to ask the code for calculator
Anonymous
2009-03-17 00:34:30
hi guys... i nid some help with this code.. as where to input the code forthe functions like +, -, %, x, / , and some other functions, if someone could help,, kindly mail me at my email add, i.Scadi@yahoo.com, pls i realy nid your help for my final project..
Anonymous
2009-03-17 01:08:41
uh. guys.. where can i found the public class form1? anyone can tell me me?
Anonymous
2009-03-17 17:17:12
this is in vb6 language, not .net. that means that i cant make one :(
CodeX
2009-03-18 07:44:46
you can, just not exactly like this :P
Anonymous
2009-03-20 00:23:15
how?did you get this code?
Anonymous
2009-04-02 13:42:47
Private Sub Command1_Click()
If List1.ListIndex = 0 Then
Div Intrest is Integer
Intrest = Text1.Text * 0.08
Text2.Text = Text1.Text + Income
End If
End Sub



whats wrong?
Anonymous
2009-04-08 18:57:01
i need code for x^2 and x^3 any help is appreciated
CodeX
2009-04-08 21:57:05
isn't it just x^2 and x^3 in VB?
Anonymous
2009-04-29 10:32:12
does any1 knw the code to find out the average??
SAJChurchey
2009-04-30 17:55:02


How does one mathematically determine an average? How could you write a single function to accomplish this?

These are the questions you should be asking yourself. We're not here to do your school project for you.
Anonymous
2009-05-10 06:36:56
this was not right . totally false codes for running calculator programming.it's a fake program.
Anonymous
2009-05-15 02:51:46
Sqrt,M,MR,MC,M+,+/-,C,CE
what is the code of this feature of calculator?
Anonymous
2009-05-27 05:26:39
It would help if you did a bit of Labeling and explaining =/. Good try on the attempt, but my personal opinion on the definition of a tutorial is to learn how to do something, then be able to like dissect it to use parts of what the reader leraned in other projects.
Anonymous
2009-06-12 16:05:17
Hey... i have a question...
Just trying to learn how to use the program, and i was wondering..

Private Sub cmdDot_Click()
If InStr(txtDisplay.Text, ".") = 0 Then
txtDisplay.Text
= txtDisplay.Text & "."
End If
End Sub

If there is a "." in the string, then write the numbers and the "." My calc works and i can put in the ".", but it works with the number as if there is no "."

Am i blind and missing something obvious??
Thx
Anonymous
2009-06-26 06:49:19
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles one.Click
one.Text = "1"
txtAnswer.Text += "1"
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAnswer.TextChanged

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles six.Click
six.Text = "6"
txtAnswer.Text += "6"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles c.Click
Dim a
txtAnswer.Text = " "



a = TxtAnswer.text

c.Text = a


End Sub

Private Sub two_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles two.Click
two.Text = "2"
txtAnswer.Text += "2"

End Sub

Private Sub three_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles three.Click
three.Text = "3"
txtAnswer.Text += "3"
End Sub

Private Sub four_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles four.Click
four.Text = "4"
txtAnswer.Text += "4"
End Sub

Private Sub five_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles five.Click
five.Text = "5"
txtAnswer.Text += "5"
End Sub

Private Sub seven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles seven.Click
seven.Text = "7"
txtAnswer.Text += "7"
End Sub

Private Sub eight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eight.Click
eight.Text = "8"
txtAnswer.Text += "8"
End Sub

Private Sub nine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nine.Click
nine.Text = "9"
txtAnswer.Text += "9"
End Sub

Private Sub zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zero.Click
zero.Text = "0"
txtAnswer.Text += "0"
End Sub

Private Sub a_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a.Click

End Sub

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

End Sub
End Class
Anonymous
2009-06-26 08:52:17
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles one.Click
one.Text = "1"
txtAnswer.Text += "1"
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAnswer.TextChanged

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles six.Click
six.Text = "6"
txtAnswer.Text += "6"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles c.Click
Dim a
txtAnswer.Text = " "



a = TxtAnswer.text

c.Text = a


End Sub

Private Sub two_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles two.Click
two.Text = "2"
txtAnswer.Text += "2"

End Sub

Private Sub three_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles three.Click
three.Text = "3"
txtAnswer.Text += "3"
End Sub

Private Sub four_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles four.Click
four.Text = "4"
txtAnswer.Text += "4"
End Sub

Private Sub five_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles five.Click
five.Text = "5"
txtAnswer.Text += "5"
End Sub

Private Sub seven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles seven.Click
seven.Text = "7"
txtAnswer.Text += "7"
End Sub

Private Sub eight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eight.Click
eight.Text = "8"
txtAnswer.Text += "8"
End Sub

Private Sub nine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nine.Click
nine.Text = "9"
txtAnswer.Text += "9"
End Sub

Private Sub zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zero.Click
zero.Text = "0"
txtAnswer.Text += "0"
End Sub

Private Sub a_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a.Click

End Sub

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

End Sub
End Class
Anonymous
2009-07-08 07:38:47
the numbers are not coming in display box
Anonymous
2009-07-08 13:43:00
mister.. dim
thx for the help!! ^^
Anonymous
2009-07-10 01:22:27
can you please help me out for the codes of calculator, i dont know the code once you got the answer for the two numbers.for example, i added 4 + 5 = 9, then the answer '9' will be divided or added etc. by another digit at he same time not clearing the screen.. a big thanks for the answer,,
Anonymous
2009-07-12 08:12:21
i need simple calculator program with the forms
kalpesh
2009-07-12 09:17:00
Option Explicit
Dim x As Double
Dim y As Double
Dim z As Double
Dim i As Integer
Dim e As Integer
Dim m As Integer
Dim a As Integer

Private Sub command1_click()
m = 1
Call inval(m)
End Sub

Private Sub Command2_Click()
m = 2
Call inval(m)
End Sub

Private Sub Command3_Click()
m = 3
Call inval(m)
End Sub

Private Sub Command4_Click()
m = 4
Call inval(m)
End Sub

Private Sub Command5_Click()
m = 5
Call inval(m)
End Sub

Private Sub Command6_Click()
m = 6
Call inval(m)
End Sub

Private Sub Command7_Click()
m = 7
Call inval(m)
End Sub

Private Sub Command8_Click()
m = 8
Call inval(m)
End Sub

Private Sub Command9_Click()
m = 9
Call inval(m)
End Sub

Private Sub Command10_Click()
m = 0
Call inval(m)
End Sub

Private Sub Command11_Click()
If e = 1 Then
Text1.Text = "."
e = e + 1
Else
Text1.Text = Text1.Text & "."
End If
End Sub

Public Function inval(ByRef x As Integer)
If e = 1 Then
Text1.Text = x
e = e + 1
Else
Text1.Text = Text1.Text & x
End If
End Function

Private Sub Command12_Click()
x = x + Val(Text1.Text)
Text1.Text = x
e = 1
i = 1
End Sub

Private Sub Command13_Click()
x = Val(Text1.Text)
e = 1
i = 2
End Sub

Private Sub Command14_Click()
x = Val(Text1.Text)
e = 1
i = 3
End Sub

Private Sub Command15_Click()
x = Val(Text1.Text)
e = 1
i = 4
End Sub

Private Sub Command16_Click()
y = Val(Text1.Text)
e = 1
Select Case i
Case 1
z = x + y
Text1.Text = z
Case 2
z = x - y
Text1.Text = z
Case 3
z = x * y
Text1.Text = z
Case 4
z = x / y
Text1.Text = z
End Select
End Sub

Private Sub Command17_Click()
Text1.Text = Sqr(Text1.Text)
e = 1
End Sub

Private Sub Command18_Click()
Text1.Text = 1 / Val(Text1.Text)
e = 1
End Sub

Private Sub Command19_Click()
x = 0
Text1.Text = "0"
e = 1
End Sub

Private Sub Command20_Click()
Text1.Text = "0"
e = 1
End Sub

Private Sub Command21_Click()
x = Val(Text1.Text)
x = x \ 10
Text1.Text = x
e = 1
End Sub

Private Sub Command22_Click()
Text1.Text = -1 * Val(Text1.Text)
e = 1
End Sub

Private Sub Command23_Click()
x = Val(Text1.Text)
e = 1
Label1.Caption = "M"
End Sub

Private Sub Command24_Click()
Text1.Text = x
Label1.Caption = "M"
e = 1
End Sub

Private Sub Command25_Click()
x = 0
Label1.Caption = ""
e = 1
End Sub

Private Sub Command26_Click()
y = Val(Text1.Text)
x = x + y
Label1.Caption = "M"
e = 1
End Sub

Private Sub Command27_Click()
y = Val(Text1.Text)
z = x * (y / 100)
Text1.Text = z
e = 1
End Sub

Private Sub Form_Load()
Text1.Text = "0"
Label1.Caption = ""
e = 1
End Sub

Private Sub Text1_keypress(KeyAscii As Integer)
If KeyAscii > 32 And KeyAscii < 42 Then
KeyAscii = 0
ElseIf KeyAscii > 57 Then
MsgBox "nonnumeric data entered", vbOKOnly, "invalid data"
KeyAscii = 0
Else
Text1.Text = Text1.Text
e = 2
End If
End Sub
Anonymous
2009-07-16 02:17:53
can u please give me all the codes regarding this calculator?

thanks!!!!!
liexhen
2009-07-26 09:34:46
_sir..plz im begging to ask for a complete code of calculator through the visual basic 6.0
Anonymous
2009-07-31 02:24:22
code for decimal point
Anonymous
2009-07-31 02:26:17
its hard to analyz
by the way wat..wat is the code of +??
Anonymous
2009-07-31 03:08:59
Public Class Form1
Dim s = 0, a As Integer
Dim op As String
Dim b As String
Dim c As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnone.Click
a = 1
txtDisplay.Text = "1"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntwo.Click
a = 2
txtDisplay.Text = "2"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthree.Click
a = 3
txtDisplay.Text = "3"
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfour.Click
a = 4
txtDisplay.Text = "4"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfive.Click
a = 5
txtDisplay.Text = "5"
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsix.Click
a = 6
txtDisplay.Text = "6"
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnseven.Click
a = 7
txtDisplay.Text = "7"
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneight.Click
a = 8
txtDisplay.Text = "8"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnine.Click
a = 9
txtDisplay.Text = "9"
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnzero.Click
a = 0
txtDisplay.Text = "0"
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdplus.Click
s = Integer.Parse(txtDisplay.Text)
op = "+"
txtDisplay.Text = ""


End Sub

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

End Sub
End Class
Anonymous
2009-07-31 03:11:36
^
^
^
wat is the problem in this code above??
can u plz help me!!

Anonymous
2009-08-02 18:19:12
i want to upload my code for calculator in vb how can i do that
Anonymous
2009-08-05 11:16:02
Private Sub cmdadd_Click()
Dim a As Variant
Dim b As Variant
Dim c As Variant
a = Val(txt1.Text)
b = Val(txt2.Text)
c = a + b
txtresult.Text = c
End Sub

Private Sub cmdsub_Click()
Dim a As Variant
Dim b As Variant
Dim c As Variant
a = Val(txt1.Text)
b = Val(txt2.Text)
c = a - b
txtresult.Text = c
End Sub


Private Sub cmdclear_Click()
txt1.Text = "0"
txt2.Text = "0"
txtresult.Text = "0"
End Sub


Private Sub smdmult_Click()
Dim a As Variant
Dim b As Variant
Dim c As Variant
a = Val(txt1.Text)
b = Val(txt2.Text)
c = a * b
txtresult.Text = c
End Sub


Private Sub cmddiv_Click()
Dim a As Variant
Dim b As Variant
Dim c As Variant
a = Val(txt1.Text)
b = Val(txt2.Text)
c = a / b
txtresult.Text = c
End Sub
Anonymous
2009-08-12 07:01:34
i want to create a code for arithmetic calculator in vb how can i do that...
Anonymous
2009-08-15 14:01:59
where should i place this code?


Private Sub Command1_Click(Index As Integer)
If txtDisplay.Text = "" Then
txtDisplay.Text
= Command1(Index).Caption
Else
txtDisplay.Text
= txtDisplay.Text & Command1(Index).Caption
End If
End Sub
Anonymous
2009-08-19 07:32:57
I find it very difficult to create a project..using visual Basic 2008..without even knowing first the version 6.0.....I'm just a beginner..
Todd434
2009-08-24 09:31:20
Right, no offence everyone but there is a really good search engine out there.

Google!

Search google for vb.net calculator, and to make it easier for you I have even got a link!

http://www.a1vbcode.com/app-4551.asp

Refrenct this Project when you are making your calculator and you should be fine, its all done for you, all you need to do is copy & paste!

Feel free to
Email me at tyopdfdf@live.co.uk

Cms me on Cyberarmy (Todd434)
http://www.cyberarmy.net

Message me on Osix (Here)

Anonymous
2009-08-27 08:45:17
what is the code for AC???ANYONE CAN HELP ME!
Anonymous
2009-08-27 08:48:21
can you give me the whole code for simple calculator??----gaspar
Anonymous
2009-08-28 15:20:41
can i know how to do the calculator matrix??
Anonymous
2009-09-14 11:33:14
Public Class Form1
Dim sum As Double = 0
Dim operand As String = ""
Dim value1 As Double = 0
Dim value2 As Double = 0
Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
txtBox1.Text += "1"
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBox1.TextChanged

End Sub

Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click
txtBox1.Text += "2"
End Sub

Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click
txtBox1.Text += "3"
End Sub

Private Sub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click
txtBox1.Text += "4"
End Sub

Private Sub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click
txtBox1.Text += "5"
End Sub

Private Sub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click
txtBox1.Text += "6"
End Sub

Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click
txtBox1.Text += "7"
End Sub

Private Sub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click
txtBox1.Text += "8"
End Sub

Private Sub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click
txtBox1.Text += "9"
End Sub

Private Sub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click
txtBox1.Text += "0"
End Sub

Private Sub btnDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click
Dim btnDot As Boolean = False
If txtBox1.Text.IndexOf(".") >= 0 Then btnDot = True
If btnDot = False Then txtBox1.Text += "."
End Sub

Private Sub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click
value2 = Val(txtBox1.Text)
Select Case operand
Case Is = "+"
txtBox1.Text = (value1 + value2).ToString
Case Is = "-"
txtBox1.Text = (value1 - value2).ToString
Case Is = "X"
txtBox1.Text = (value1 * value2).ToString
Case Is = "/"
If value2 <> 0 Then
txtBox1.Text = (value1 / value2).ToString
End If
End Select
End Sub

Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click
operand = "+"
If checkInput() = True Then value1 = CDbl(txtBox1.Text)
txtBox1.Clear()


End Sub

Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click
operand = "-"
If checkInput() = True Then value1 = CDbl(txtBox1.Text)
txtBox1.Clear()

End Sub

Private Sub btnTimes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimes.Click
operand = "X"
If checkInput() = True Then value1 = CDbl(txtBox1.Text)
txtBox1.Clear()

End Sub

Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click
operand = "/"
If checkInput() = True Then value1 = CDbl(txtBox1.Text)
txtBox1.Clear()

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtBox1.Clear()
sum = 0
End Sub
Private Function checkInput() As Boolean
If IsNumeric(txtBox1.Text) = True And txtBox1.Text <> "" And txtBox1.Text <> Nothing Then
Return True
Else
Return False

End If
End Function
adibah
2009-09-15 19:02:26
im searching for searching coding in vb. example, im searching harry,, and my result will display all harry names in my database. is there any coding for it, doesn't it impossible?
Anonymous
2009-09-25 03:18:52
please give e a calculator program in visual basic
Anonymous
2009-09-26 13:02:35
Hi, can you help to make a simple calculator in visual basic. the code just like a simple calculator in computer..tnx send to this email Alan_JaNDy2009@yahoo.com
Anonymous
2009-10-05 04:10:11
thanks for help me on the calcular program i expect more on the vb.net
thank you
Anonymous
2009-10-07 03:21:08
thanks for the creator codes in java thank3X..


>>LEE MIN HO<<
Anonymous
2009-10-09 02:21:17
can you plz. help me making a code for calculatiions in vb with 1 textbox and has diff, commands....?????////>>><<><>>
thank you in advance,,,,



<<<<<kill_hitman>>>>>>
Anonymous
2009-10-18 08:22:35
Any want want help in visual studio code generation then contact with me...

my id is Aaqibrashid@hotmail.com
Anonymous
2009-10-20 23:31:23
Guys, I am a rookie in VB 2008 and am designing a calculator with those detils:
textbox1
textbox2
textboxDisplay3

btnPlus
btnMinus
btnTimes
btnDivide
=
lblDisplayOperator ' to display the sign e.g +,-,x and / when for example btnPlus is clicked it will display textbox1 + textbox2 = texboxDisplay3

on top of that I have to check the value of numbers that it is more than zero (0) and less than 100....

any help would be appreciated
this is my code which is taking me ages.

what I think im missing is the code that goes in the button_click event i.e. button_plus, minus, divide and times
--------------------------------------------------


Public Class New_Calculator_Form
' Author: Avni Coga
' Date: 20 October 2009
'Description: The user will input two number in two separeate text boxes and click on the +,-,x,/ operators where it
'will display the opeartor symbol and the answer in a separate text box, also it will check that the number is inbetween 1 - 100.

' declaring the global variables
Dim num1 As Integer
Dim num2 As Integer
Dim TotalSum As Integer

Private Function DivideError(ByVal Error1 As Single, ByVal Error2 As Single)
Dim ErrValue As Boolean ' declaring the variable as boolean True/False

'checks the value for True or false
If Error1 > 1 Then
ErrValue = False
ElseIf Error2 < 99 Then
Error2 = False
Else
ErrValue = True
End If
Return ErrValue
End Function

Private Function AddNumbers(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim aOperator, Plus, Minus, Multiply, Divide As String
Dim LocalTotal As Integer
Plus = aOperator
Minus = aOperator
Multiply = aOperator
Divide = aOperator

Select Case aOperator
Case "+"
aOperator = "+"
LocalTotal = num1 + num2
Case "-"
aOperator = "-"
LocalTotal = num1 - num2
Case "/"
aOperator = "/"
LocalTotal = num1 / num2
Case "*"
aOperator = "*"
LocalTotal = num1 * num2
End Select

TotalSum = LocalTotal ' local sum gets assigned to Totalsum
Return TotalSum 'return the totalsum

End Function

Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click
Dim x As Integer ' declaring x as integer

num1 = txtbox1.Text ' assig the values of num1 & num2 to texbox1 and 2
num2 = txtbox2.Text
x = AddNumbers(num1, num2) 'assigning the value of "num1, num1 " to x
' displaying the value of "x" to text box display
txtboxDisplayTotal.Text = TotalSum

End Sub

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

End Sub

Private Sub btnTimes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimes.Click

End Sub

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

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close() 'Exit the program
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtbox1.Clear() 'Clear all the text boxes
txtboxDisplayTotal.Clear()
txtbox2.Clear()
End Sub


End Class

respect Nino.
avni.coga@gmail
Anonymous
2009-10-28 03:17:33
wow!!!
Anonymous
2009-10-28 09:04:58
its good!!
Anonymous
2009-11-09 17:45:34
lollllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
Anonymous
2009-11-21 20:52:51
plz, show a image of calculator which is design by you....
Anonymous
2009-11-25 08:53:03
Pls display also the picture of calculator using VB and also a codes ^_^
Anonymous
2009-11-28 00:39:09
i have a calculator that fully functions but i have to make it so that i cant write more then one zero (000) in the textbox ;
could someone help please? thanks !
Anonymous
2009-12-07 13:09:44
PLEASE READ excuse me but how will you handle the error when the user clicks on a button(example 1) then he clicks on the plus sign and then clicks on the multiplication sign and then a clicks the 2nd number - it is suppose to be the multiplication sign that will run. but how will i do it? i am having a hard time with this tnx
Anonymous
2009-12-11 10:28:08
wew .
i cant understand guyz ..
hmm i jast wanna ask how to make a LOG-IN PASSWORD project in vB6.0 ??
please do it in a simple way ..
im only a high school student ..
thanks !
Anonymous
2009-12-15 18:33:04
mi ni zona &#351;&#305;ma va se
Anonymous
2009-12-15 18:34:04
mi nie zoana shima va se
Anonymous
2009-12-17 17:21:21
koe mari help ker da plz
Anonymous
2009-12-23 18:14:43
it didn't have a message box how i can creat it and how i assign the button and how many button and label do i assign to this
Anonymous
2010-01-06 03:32:09
hey, im not very good with VB and i have a final about making a calculator in which i can input up to 3 numbers at a time with add, sub, mult, div in it even if you could send me an example on how to get started it would really help me if someone could send me code to my e-mail <buffyslyr16@sbcglobal.net> well thank you if you take the time to help me
Anonymous
2010-01-08 12:15:26
Gret stuff I love these tutorials
Como ganar mas dinero
[url=http://ganarmasdineroya.webs.tl/]Ganar mas dinero ya/url]
Anonymous
2010-01-13 06:20:31
helpppppppppppppppppppppppppppp.........
Anonymous
2010-01-17 12:49:48
thanks for the other code of calculator
i learn
Anonymous
2010-01-21 14:54:44
who knows the code on how to store numbers in a calculator?
i cant use TempValue = Display.Caption. its not applicable.
Anonymous
2010-01-31 00:16:19
how can i make a command of button for positive and negative sign for vb 2005?
Anonymous
2010-02-09 06:56:39
Advanced Calculator:
http://www.reflectionforbrain.com/form/CalculatorT.htm
Anonymous
2010-02-09 06:57:52
Advanced Calculator:
<a href="http://www.reflectionforbrain.com/form/CalculatorT.htm"> Visual Basic 2008 Calculator</a>
Anonymous
2010-02-09 07:00:15
[pop h=200, w=250, http://www.reflectionforbrain.com/form/CalculatorT.htm] Visual Basic 2008 Calculator[/pop]
Anonymous
2010-02-09 07:01:49
http://www.reflectionforbrain.com/form/CalculatorT.htm
Anonymous
2010-02-16 09:01:16
Thanks kindly, very helpful code
Anonymous
2010-02-16 23:16:08
i really need codes for my assignment in vb in order to pass my subject...

can u help me?...
im running out of time..T_T...
i should submit it tommorow..
please sir.....
ur my last chance....

ill wait for your help sir.....
(k_iiiii_m@yahoo.com) my email add sir....
thanks in advance....
Anonymous
2010-02-19 07:49:29
can u please give me some codes of +/- in calculator at vb.net
Anonymous
2010-03-09 07:11:21
WEEE. . tnx for the code!!
Anonymous
2010-03-09 14:24:50
i am having problem with my sign. when i'm testing it, the debug window kees coming out. can you help me?
Anonymous
2010-03-15 22:52:17
what is visual basic?
Anonymous
2010-03-15 22:53:01
what even is visual basic and where do you get it?
Anonymous
2010-03-21 08:58:00
Hi i'm new to VB, i need to create a calculator in visual basic 6.0 that contains psuedocode.My email is : thecrazycrickiter@hotmail.com. also if anyone knows how to create an average within the calculator it would be greatly appreciated. I'm doing a school assignment so try make it look like a kid version but no to basic. Thanks heaps.
Anonymous
2010-03-21 11:00:42
get back to me as soon as possible plz
Anonymous
2010-11-15 02:33:13
Public Class PresentValueForm
Private Sub PresentValueForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'declare variables to store user input
Dim future As Decimal ' store future value
Dim rate As Double ' store interest rate
Dim amount As Decimal ' store each calculation
Dim output As String ' store output

' retrieve user input
future = Val(futureValueTextBox.Text)
rate = Val(rateTextBox.Text)

' set output header
output = "Years" & ControlChars.Tab _
& "Amount on Deposit Needed" & ControlChars.CrLf
'calculate amount after each yearand append to string
For yearCounter As Integer = 1 To yearUpDown.Value
amount = _
future * ((6.6 / 5, 10, 15 * 12, -100)) ^ yearCounter)
output &= (yearCounter & ControlChars.Tab & _
String.Format("(o:C)", amount) & ControlChars.CrLf)

Next

resultsTextBox.Text = output ' display result
End Sub 'calculateButton_Click
Anonymous
2010-11-19 09:35:39
IT' S VERY USEFUL. Want to expect a more examples.if comparing to other web page eg its very useful
Anonymous
2010-11-19 15:08:43
thanks, it's useful enough.but can you help me with this part?
second = Label1.Caption

If sign = "-" Then
Label1.Caption = first - second
ElseIf sign = "+" Then
Label1.Caption = first + second
ElseIf sign = "*" Then
Label1.Caption = first * second
ElseIf sign = "/" Then
Label1.Caption = first / second
End If

because everytime i enter it, the vb said it argument not optional.
Anonymous
2010-11-22 12:34:34
gud
Anonymous
2010-11-23 07:14:32
dcdfxcdsfffffffffffffffffffd
ibs
2010-11-25 07:18:07
Have a nice day! could you please help me for my new project? i made a converter in excel and i want to make it in Visual Studio the formulas is this (Raw Material qty. 95
% from Formulation 38.5
Pro. Required 246.7532468 or 95/38.5*100)
Please help me!!
Anonymous
2010-11-28 14:51:40
is 10 dividable by 0?
Anonymous
2010-11-30 08:06:30
Its Good but i want the exact codes for Positive Negative sign,,,,,,,,,,
Anonymous
2010-12-01 08:43:40
im using vb6.0 and i have noticed that this calcu;ator uses another version of visual basic, i wonder if anyone can give me the prop[er code for calculator program in vb6.0,
thanks
Anonymous
2010-12-18 05:15:46
PLEASE I NEED HELP completing my project

I already have most of the code complete for my calculator problem

I only have two problems

1) My calculator program need to run just as the calculator program in windows

this is my email PLEASE HELP ME I NEED IT

flakq8@hotmail.com
Anonymous
2010-12-27 12:28:20
hi sir i like know sin & cos & tan & Degree & Radians & x^y & +\- for the VB if we know tel us pleas..........
bahonar_mozek@yahoo.com
send to me
Anonymous
2011-01-02 22:58:24
hi, i need code or some exsample for; prevent entering a . (dot) from keyboard to textbox second time
Anonymous
2011-01-10 07:17:26
i don't understand,., sorry
Anonymous
2011-01-10 11:11:27
i like this. keep it up to educate us.
Anonymous
2011-01-11 14:59:44
wew...my problem is when i try to click a decimal no... ending with zero... its not working for example,.. i type 12.0 it become.. 120. u know what i mean?the point seems to be not working.... can someone help me?heres my code.. in my calcu

Anonymous
2011-01-16 06:11:05
sir pls. help me for my assignment...,our instructor give us a assignment to make a calculator.., but I can't complete it..., what is the code of sqrt,% 1/x, MC, MR, MS M+, and the backspace..., I hope you can help me..., thank you.. This is my Email... sweetruss_16@yahoo.com.
Anonymous
2011-01-19 17:26:54
YAR PLZ UP LOAD WITH PICTURE. AND ALSO SOW WHICH IS TEXT OR LAIR YA BUTTONS.
Anonymous
2011-01-20 05:11:17

2011-01-16 06:11:05
sir pls. help me for my assignment...,our instructor give us a assignment to make a calculator.., but I can't complete it..., what is the code of sqrt,% 1/x, MC, MR, MS M+, and the backspace..., I hope you can help me..., thank you.. This is my Email ...hongc_901@hotmail.com
Anonymous
2011-01-20 10:01:04
Calculator code..... (Bckspc is not perfect)

Dim a, b, c, e, z As String
Dim x, y As Integer

Private Sub Command1_Click()
If a <> 0 Then
a = a + "0"
Text1.Text = Val(a)
End If
End Sub

Private Sub Command10_Click()
a = a + "7"
Text1.Text = Val(a)
End Sub

Private Sub Command11_Click()
If a <> "" Then
b = (Val(b) + Val(1)) * Val(a) - Val(a)
a = ""
End If
e = "3"
y = 0
End Sub

Private Sub Command12_Click()
y = 0
If a = "" Then
a = "1"
ElseIf a = 0 Then
x = MsgBox("Divide by zero error", 16, "Warning")
Unload Form1
Load Form1
Form1.Show
Exit Sub
b = Val(b) / Val(a)
ElseIf b = 1 Then
b = Val(a)
End If
a = ""
e = "4"
End Sub

Private Sub Command13_Click()
y = 0
If c <> 0 Then
c = Val(c) - Val(a)
Else
c = Val(a) - Val(c)
End If
a = ""
e = "2"
End Sub

Private Sub Command14_Click()
y = 0
c = Val(a) + Val(c)
a = ""
e = "1"
End Sub

Private Sub Command15_Click()
y = 0
If b = 1 Then
b = Val(a)
ElseIf a = "" Then
a = "1"
ElseIf a = 0 Then
x = MsgBox("Divide by zero error", 16, "Warning")
Unload Form1
Load Form1
Form1.Show
Exit Sub
b = Val(b) Mod Val(a)
End If
a = ""
e = "5"
End Sub

Private Sub Command16_Click()
y = 0
If b = 0 Then
b = "1"
End If

If e = "1" Then
c = Val(a) + Val(c)
Text1.Text = c
b = c

ElseIf e = "2" Then
If c <> 0 Then
c = Val(c) - Val(a)
Else
c = Val(c) - Val(a)
End If
Text1.Text = c
b = c

ElseIf e = "3" And a <> "" Then
b = (Val(a) + Val(1)) * Val(b) - Val(b)
Text1.Text = b
c = b

ElseIf e = "4" And a <> "" Then
If a = 0 Then
x = MsgBox("Divide by zero error", 16, "Warning")
Unload Form1
Load Form1
Form1.Show
Exit Sub
ElseIf b = 1 Then
b = Val(a)
Else
b = Val(b) / Val(a)
End If
Text1.Text = b
c = b

ElseIf e = "5" And a <> "" Then
If a = 0 Then
x = MsgBox("Divide by zero error", 16, "Warning")
Unload Form1
Load Form1
Form1.Show
Exit Sub
ElseIf b = 1 Then
b = Val(a)
Else
b = Val(b) Mod Val(a)
End If
Text1.Text = b
c = b
End If
a = ""
End Sub

Private Sub Command17_Click()
Unload Form1
Load Form1
Form1.Show
End Sub

Private Sub Command18_Click()
If y = 0 Then
a = a + z
Text1.Text = a
y = 1
End If
End Sub

Private Sub Command19_Click()
a = Text1.Text
x = Val(a) Mod 10
a = Val(a) - x
a = Val(a) / 10
a = Str(a)
Text1.Text = a
b = a
c = a
a = ""
End Sub

Private Sub Command2_Click()
a = a + "3"
Text1.Text = Val(a)
End Sub

Private Sub Command20_Click()
End
End Sub

Private Sub Command3_Click()
a = a + "6"
Text1.Text = Val(a)
End Sub

Private Sub Command4_Click()
a = a + "9"
Text1.Text = Val(a)
End Sub

Private Sub Command5_Click()
a = a + "2"
Text1.Text = Val(a)
End Sub

Private Sub Command6_Click()
a = a + "5"
Text1.Text = Val(a)
End Sub

Private Sub Command7_Click()
a = a + "8"
Text1.Text = Val(a)
End Sub

Private Sub Command8_Click()
a = a + "1"
Text1.Text = Val(a)
End Sub

Private Sub Command9_Click()
a = a + "4"
Text1.Text = Val(a)
End Sub

Private Sub Form_Load()
b = "1"
c = "0"
y = 0
z = "."
End Sub

------- By Sadanand Akshay Pai----------
Anonymous
2011-01-22 13:12:41
hi am making a scientific calculator but i have a problem with coding pliz help
Anonymous
2011-01-24 08:57:28
plz help me program a standard calculator. pls i nid it within a weak. im using ms visual basic 2005. plz help
Anonymous
2011-01-26 23:56:34
Ok well this code tremendously helped me its just how do you code your program to have txtDisplay.Text show ERROR if the user divides by zero?
Anonymous
2011-01-31 10:10:03
hi
Anonymous
2011-02-07 06:42:06
..hey there, i am one of the many beginners in vb.net..could you help the code for the backspace in my simple calculator..or in order to delete the current number the is type..please any1..help ^^
<amz>
Anonymous
2011-02-10 05:23:09
i am chaitanya.i didn't understand ur program can u explain the program
Anonymous
2011-02-11 14:56:43
mine works good ta mate
Anonymous
2011-02-11 14:57:39
isaac ryan ryan and matty
Anonymous
2011-02-15 10:06:37
Hi All
A much more elegant way as follows...

Private Sub Numeric_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_0.Click, Btn_1.Click, Btn_2.Click, Btn_3.Click, Btn_4.Click, Btn_5.Click, Btn_6.Click, Btn_7.Click, Btn_8.Click, Btn_9.Click, Btn_Point.Click

'handles 0123456789 from button press
Dim ButtonValue As String
Dim btnNumericButton As Button

btnNumericButton = sender
ButtonValue = btnNumericButton.Text
MsgBox(ButtonValue)

End Sub

make sure the button has the name from the handles part of the sub declaration (i.e. Btn_1) and the text on the button is 1. Then this sub will simply handle entered numbers from 0-9. This will show a message box of the number pressed, use it however... Al
Anonymous
2011-02-16 08:35:14
how can i put the decimal button?
Anonymous
2011-02-16 16:48:03
hi all
what is the square root code?
Anonymous
2011-02-18 03:36:16
please help me, i really don't no how to make this program run.........please give me a short and understandable code for calculator program in vb
Anonymous
2011-02-18 15:41:18
Text3.text=text1.text+text2.text
you all fuck off
Anonymous
2011-02-18 15:41:44
Text3.text=text1.text+text2.text
you all fuck off
Anonymous
2011-02-26 13:56:10
can anyone help me on how to limit the decimal point into one for every set of number??.. please!!! then after pressing an operation it can be enabled again.. please help! thankyou
Anonymous
2011-03-14 04:35:54
:))
Anonymous
2011-03-16 06:24:14
nice.
Anonymous
2011-05-04 10:54:34
Sir could you please send me the simple billing software programming code based on vb6.
Tirtha Ojha
rj.tirtha@gmail.com
Anonymous
2011-05-04 17:24:31
sir could u send me vb.net software at my email address .i am not able to download that from net or to get the right one from market ...tamal sadhu at tamalsaadhu@gmail.com
Anonymous
2011-06-18 14:46:19
nice...
Anonymous
2011-06-23 07:21:29
hey buddie it z really amazing i just lov dis demonstration.....it can be understand easily.....!@!!!
Anonymous
2011-06-24 12:27:33
I want to know how to create a notepad in visual basic 6.0, using the MDI form.
Anonymous
2011-06-24 12:34:50
i want to know, how to create an active notepad in visual basic 6.0, using MDI form with basic file, edit and help menu including every menu content? Please mail: findmebenjamindaviesjr@yahoo.com. I really need to submit this assignment. Thanx in Advance!!!
Anonymous
2011-06-24 12:38:49
Please help me with codes and step through explanation on how create a simple hand calculator in visual basic 6.0. I AM JUST A BEGINNER!! Please mail it: findmebenjamindaviesjr@yaho.com. Thanx in Advance!
Anonymous
2011-06-24 12:39:56
Please help me with codes and step through explanation on how create a simple hand calculator in visual basic 6.0. I AM JUST A BEGINNER!! Please mail it: findmebenjamindaviesjr@yaho.com. Thanx in Advance!
Anonymous
2011-06-28 06:06:24
Public Class Calculadora

Dim d As String = ""


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
d = d & "1"
TextBox1.Text = d
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
d = d & "2"
TextBox1.Text = d
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
d = d & "3"
TextBox1.Text = d
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
d = d & "4"
TextBox1.Text = d
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
d = d & "5"
TextBox1.Text = d
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
d = d & "6"
TextBox1.Text = d
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
d = d & "7"
TextBox1.Text = d
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
d = d & "8"
TextBox1.Text = d
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
d = d & "9"
TextBox1.Text = d
End Sub

Private Sub Button0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click
d = d & "0"
TextBox1.Text = d
End Sub

Private Sub ButtonSumar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSumar.Click
d = d & "+"
TextBox1.Text = d


End Sub

Private Sub ButtonBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBorrar.Click
d = ""
TextBox1.Text = ""
End Sub

Private Sub ButtonRestar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRestar.Click
d = d & "-"
TextBox1.Text = d

End Sub

Private Sub ButtonIgual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonIgual.Click
Dim SC As New MSScriptControl.ScriptControl
Dim Formula As String = TextBox1.Text
'SET LANGUAGE TO VBSCRIPT
SC.Language = "VBSCRIPT"
'ATTEMPT MATH
Try
Dim Result As Double = Convert.ToDouble(SC.Eval(Formula))
'SHOW THAT IT WAS VALID
TextBox1.Text = Result.ToString
Catch ex As Exception
'SHOW THAT IT WAS INVALID
MessageBox.Show("Error en la formula favor de corregir.")
End Try
End Sub

Private Sub ButtonMultiplicar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMultiplicar.Click

d = d & "*"
TextBox1.Text = d
End Sub

Private Sub ButtonDividir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDividir.Click
d = d & "/"
TextBox1.Text = d
End Sub

Private Sub ButtonPrueba_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub ButtonElevar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonElevar.Click
d = d & "^"
TextBox1.Text = d
End Sub
End Class

As you can see is very easy, you can even type teh ecuation to the text box just 1 thing you have to add the reference Microsoft Script Control 1.0
Anonymous
2011-07-02 00:44:27
Please Sir, I am working on Hospital Data Base, I created a simple software in VB 6.0, but my problem is: How to code the Find button to search and display information about the person. Please Help me with this code please...
Anonymous
2011-07-02 00:52:16
I have tried but I am tied, but I would not give up until I get the target.

Please help me with the code in VB that can be used to attach Passport to a picture holder at the Run time please. Help me by sending it to zoelike203@yahoo.co.uk and I will forever remain grateful to you and God. Please I beg of you, Help me...
Anonymous
2011-07-02 14:32:30

Private Sub Command1_Click()
Text1.Text = Text1.Text + "1"
End Sub

Private Sub Command10_Click()
Text1.Text = ("")
End Sub

Private Sub Command11_Click()

Text1.Text = Text1.Text + "0"
End Sub


Private Sub Command12_Click()
b = Text1.Text
Select Case d%
Case 1: c = a + b
Text1.Text = c
Case 2: c = a - b
Text1.Text = c
Case 3: c = a * b
Text1.Text = c
Case 4: c = a / b
Text1.Text = c
End Select


End Sub

Private Sub Command13_Click()
a = Text1.Text
Text1.Text = "+"
d = 1
End Sub

Private Sub Command14_Click()
a = Text1.Text
Text1.Text = "-"
d = 2

End Sub

Private Sub Command15_Click()
a = Text1.Text
Text1.Text = "*"

d = 3

End Sub

Private Sub Command16_Click()
a = Text1.Text
Text1.Text = "/"
d = 4

End Sub

Private Sub Command18_Click()
a = Text1.Text
Text1.Text = "*"
c = a * a
Text1.Text = c

End Sub

Private Sub Command2_Click()

Text1.Text = Text1.Text + "2"
End Sub

Private Sub Command3_Click()

Text1.Text = Text1.Text + "3"
End Sub
Private Sub command4_click()
Text1.Text = Text1.Text + "4"

End Sub


Private Sub Command5_Click()

Text1.Text = Text1.Text + "5"
End Sub

Private Sub Command6_Click()

Text1.Text = Text1.Text + "6"
End Sub

Private Sub Command7_Click()

Text1.Text = Text1.Text + "7"
End Sub

Private Sub Command8_Click()

Text1.Text = Text1.Text + "8"
End Sub

Private Sub Command9_Click()

Text1.Text = Text1.Text + "9"
End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub
wher is the mistake please find it
Anonymous
2011-07-04 14:07:32
will someone please create a visual basic calculator without decimal point.?

in the way like this

example output
5 / 2 = 2
1/0 = Error
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Test Yourself: (why not try testing your skill on this subject? Clicking the link will start the test.)
VB Potpourri: Programming, History And Syntax by batterseapower

A nice little collection of the basics of Visual Basic.
Advanced Programming Techniques by batterseapower

A fiendish test covering some of the more obscure elements of Visual Basic 6.


     
Your Ad Here
 
Copyright Open Source Institute, 2006