A Simple Windows Like Calculator in Visual Basic 6. See the Screenshot. Keyboard Shortcuts Ascii code of '0' is '48' and is a short cut key to '0' Ascii code of '1' is '49' and is a short cut key to '1' Ascii code of '2' is '50' and is a short cut key to '2' Ascii code of '3' is '51' and is a short cut key to '3'. Title your calculator. To change the text that appears at the top of the calculator's window when you run it, do the following: Click a blank space on the form. Click the 'Caption' header's text box in the 'Properties' pane. Type in Simple Calculator (or whatever you want to name the calculator). If you pick up a cheap calculator, you will find that this is how they work. If you press 3 × 4 +, pressing + instructs the calculator to complete the previous calculation of 3 × 4 and puts + on the operator stack. Then if you press 2 = it uses the value in the accumulator (12) and completes the next operation + 2 resulting in 14. This is the snippet Simple Calculator on FreeVBCode. The FreeVBCode site provides free Visual Basic code, examples, snippets, and articles on a variety of other topics as well. Create a New Project. First things first, create a new C# project by going to File New and choose.
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
Visual Basic Calculator Project
'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
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
End If
End 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)
Simple Calculator In Visual Studio
End IfEnd 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
How to write a visual basic program. Visual Basic programs for beginners with examples. How to print a string in visual basic. below are some examples of visual basic programs.
In this tutorial, Will see some basic string operation like how to print string and char in visual basic. Check thevisual basic program for mathematical operations.
Let’s start with the basic “Hello World” Project in Visual basic. Start any programming language with some string operation is a really good idea.
Write a visual basic program to print a string “Hello World”
The below code will print the string value “Hello World”. Console.WriteLine(” “) is used to print any value as an output and the Console.ReadLine() is used to read the next line here we are using it to hold the screen.
Output: Hello World
Visual basic program to print a string variable.
Declare a variable in visual basic is really simple. here in the below code. Dim str As String is a variable decoration. Where str is a variable of string type.
Output: Write First Program in Visual basic
How to Concat two string in Visual basic.
+ or the & operator is used to Concat two or more string in Visual basic. Below is the code to Concat two string in visual basic. Which contains 3 strings str1, str2,str3.
Output: Visual basic program
Please check more examples on visual basic program for beginner
Visual Basic programs with example
Basic Vb programs
Example 2.1.1 |
Example 2.1.2 |
You can also use the + or the & operator to join two or more texts (string) together like in example 2.1.4 (a) and (b)
Example 2.1.4(a) Private Sub A = “Tom” End Sub | Example 2.1.4(b) Private Sub A = “Tom” End Sub |
Write a VB program to convert Celsius to Fahrenheit