- This wikiHow teaches you how to use Microsoft's Visual Basic 6.0 to create a simple calculator that can add, subtract, multiply, and divide. Keep in mind that Visual Basic 6.0 is no longer used by modern computers, so you'll need to have it installed and running on your computer in order to be able to use it.
- Code Download: http:/www.schoolfreeware.comThe Data Type Summery (Visual Basic) can be found on Microsoft's MSDN Websitehttp://msdn.microsoft.com/en-us/libra.
- In this example, you build a very simple calculator named SimpleCalculator. The goal of SimpleCalculator is to create a console application that accepts basic arithmetic commands, in the form '5+3' or '6-2', and returns the correct answers. Using MEF, you will be able to add new operators without changing the application code.
- Calculator using Excel VBA UserForm:Project Objective Calculator using Excel VBA UserForm. Following is the step by step detailed explanation to automate this project using VBA. How we are doing calculations, clear the text, etc.
Calculator How To Create A Calculator In VB.NET How To Make A Calculator Using VB.NET VB.NET VB.NET Calculator Source Code VB.NET Calculator How To Create A Calculator In VBNET In This VB.NET Tutorial we will See How To Make A Simple Windows Form Calculator Application With Swith To Do The Basic Operations (+, -, /,.) And Reset To Make Another.
This are the Codes :
Public Class frmcalculator
Dim Operand1 As Double
Dim Operand2 As Double
Dim [Operator] As String
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click, Button2.Click
txtsource.Text = txtsource.Text & sender.text
End Sub
Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
txtsource.Text = '
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = '
txtsource.Focus()
[Operator] = '+'
End Sub
Private Sub btndecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If InStr(txtsource.Text, '.') > 0 Then
Exit Sub
Else
txtsource.Text = txtsource.Text & '.'
End If
End Sub
Private Sub btnequals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Result As Double
Operand2 = Val(txtsource.Text)
'If [Operator] = '+' Then
' Result = Operand1 + Operand2
'ElseIf [Operator] = '-' Then
' Result = Operand1 - Operand2
'ElseIf [Operator] = '/' Then
' Result = Operand1 / Operand2
'ElseIf [Operator] = '*' Then
' Result = Operand1 * Operand2
'End If
Select Case [Operator]
Case '+'
Result = Operand1 + Operand2
MsgBox(Result.ToString('#,###.00'), MsgBoxStyle.Information, 'Result')
txtsource.Text = Result.ToString('#,###.00')
Case '-'
Result = Operand1 - Operand2
MsgBox(Result.ToString('#,###.00'), MsgBoxStyle.Information, 'Result')
txtsource.Text = Result.ToString('#,###.00')
Case '/'
Result = Operand1 / Operand2
Simple Calculator In Visual Studio
MsgBox(Result.ToString('#,###.00'), MsgBoxStyle.Information, 'Result')
txtsource.Text = Result.ToString('#,###.00')
Case '*'
Result = Operand1 * Operand2
MsgBox(Result.ToString('#,###.00'), MsgBoxStyle.Information, 'Result')
txtsource.Text = Result.ToString('#,###.00')
End Select
txtsource.Text = Result.ToString('#,###.00')
End Sub
Private Sub btnminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnminus.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = '
txtsource.Focus()
[Operator] = '-'
End Sub
Private Sub btnmultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmultiply.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = '
txtsource.Focus()
[Operator] = '*'
End Sub
Private Sub btndivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndivide.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = '
txtsource.Focus()
[Operator] = '/'
End Sub
Private Sub btnaddminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
txtsource.Text = -1 * txtsource.Text
End Sub
Private Sub btnx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnx.Click
Dim convert As Single
If txtsource.Text <> 0 Then
convert = 1 / Val(txtsource.Text)
txtsource.Text = convert
Visual Basic Simple Calculator Code
End IfEnd Sub
Private Sub frmcalculator_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
Call btnequals_Click(sender, e)
End If
End Sub
Private Sub frmcalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
End Class
Visual Basic 6 is a third-generation event-driven programming language first released by Microsoft in 1991. In VB 6, there is no limit of what applications you could create, the sky is the limit. You can develop educational apps, financial apps, games, multimedia apps, animations, database applications and more.
The team at vbtutor.net has created many sample codes, please browse them on the sidebar. You are welcome to use the sample codes as a reference for your assignments and projects. However, the usage of the sample codes for commercial purposes without prior consent from the webmaster is strictly prohibited.
Visual Basic Sample Codes E-Book is written by our webmaster, Dr.Liew. It comprises 258 pages of captivating contents and 48 fascinating Sample Codes.Perfect source of reference for your VB projects. Check it out.
About Us
The Tutor and webmaster of Vbtutor.net, Dr.Liew Voon Kiong , holds a Bachelor's Degree in Mathematics, a Master's Degree in Management and a Doctoral Degree in Business Administration. He obtained the DBA degree from the University of South Australia.
Create Calculator In Visual Basic
He has been involved in programming for more than years. He created the popular online Visual Basic Tutorial in 1996 and since then the web site has attracted millions of visitors .It is the top-ranked Visual Basic tutorial website in many search engines including Google. Besides that, he has also written a few Visual Basic related books. One of the books, Visual Basic 6 Made Easy was published by Creativespace.com, an Amazon.com publisher.
The Slot Machine created using VB6
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy