0

# Vb calculator code

Updated: 4/28/2022

Wiki User

14y ago

In visual basic 6.0:

Public input1, input2, number1, output, decimal2, operand, input3 As Double

Public operand2, oprand3 As String

Public decimal3 As Boolean

'Input

Private Sub Command1_Click(Index As Integer)

number1 = number1 + 1

'input1 decimal

If operand = 0 And decimal3 = True Then

number2 = 1 * (10 ^ (number1 - 1))

decimal2 = Index / number2

input1 = input1 + decimal2

Text1.Text = input1

End If

' input2 decimal

If operand > 0 And decimal3 = True Then

number2 = (1 * (10 ^ (number1 - 1)))

decimal2 = Index / number2

input2 = input2 + decimal2

Text1.Text = input1 & " " & operand2 & " " & input2

End If

'input1 single digits

If number1 < 2 And operand < 1 And decimal3 = False Then

input1 = Index

Text1.Text = input1

End If

' input1 multiple digits

If number1 > 1 And operand < 1 And decimal3 = False Then

input1 = (input1 * 10) + Index

Text1.Text = input1

End If

'input2 single digit

If operand > 0 And number1 < 2 And decimal3 = False Then

input2 = Index

Text1.Text = input1 & operand2 & input2

End If

'input2 multiple digits

If number1 > 1 And operand > 0 And decimal3 = False Then

input2 = (input2 * 10) + Index

Text1.Text = input1 & operand2 & input2

End If

End Sub

' Plus/Minus

Private Sub Command2_Click()

If operand < 1 Then

input1 = -1 * input1

Text1.Text = input1

End If

If operand > 1 Then

input2 = -1 * input2

Text1.Text = input1 & " " & operand2 & " ( " & input2 & " ) "

End If

End Sub

' Equals

Private Sub Command3_Click()

Select Case operand

Case Is = 1

output = input1 + input2

Text1.Text = input1 & operand2 & input2 & "=" & output

Case Is = 2

output = input1 - input2

Text1.Text = input1 & operand2 & input2 & "=" & output

Case Is = 3

output = input1 / input2

Text1.Text = input1 & operand2 & input2 & "=" & output

Case Is = 4

output = input1 * input2

Text1.Text = input1 & operand2 & input2 & "= " & output

End Select

input3 = output

number1 = 0

input1 = 0

input2 = 0

output = 0

operand = 0

number2 = 0

decimal2 = 0

decimal3 = False

End Sub

'Plus

Private Sub Command4_Click()

operand = 1

operand2 = "+"

Text1.Text = input1 & operand2

number1 = 0

number2 = 0

decimal3 = False

End Sub

'Minus

Private Sub Command5_Click()

operand = 2

operand2 = "-"

Text1.Text = input1 & operand2

number1 = 0

number2 = 0

decimal3 = False

End Sub

'Divide

Private Sub Command6_Click()

operand = 3

operand2 = "/"

Text1.Text = input1 & operand2

number1 = 0

number2 = 0

decimal3 = False

End Sub

' Multiply

Private Sub Command7_Click()

operand = 4

operand2 = "*"

Text1.Text = input1 & operand2

number1 = 0

number2 = 0

decimal3 = False

End Sub

' POINT

Private Sub Command8_Click()

decimal3 = True

End Sub

' ANS

Private Sub Command9_Click()

If operand = 0 Then

input1 = input3

Text1.Text = input1

End If

If operand > 0 Then

input2 = input3

Text1.Text = input1 & " " & operand2 & " ( " & input2 & " ) "

End If

End Sub

This can be transalted into other VB scripts as the code is quite simple and easy to follow however i have put headings for each section as a guide to it's function

Wiki User

14y ago

Earn +20 pts
Q: Vb calculator code
Submit
Still have questions?
Related questions

### Source code for calculator in vb 6.0?

high level language

form1.vb

vvbvcvbn vb

wrtrwtgfe

### Where you can get source code for vb projects?

you can get lots of source code from 1000projects.com in diff languages....

yes

yes

### How can you write code for a metric converter in vb?

The answer will depend which attribute you wish to convert.

### How do you convert a pdf file into a doc file using VB code?

You will need a PDF server running somewhere that can be accessed by your VB code. It will need to be called from the code through the server and get the PDF file in return. I did that with Tweak PDF Converter, an pdf editor for converting pdf file to word form.

### What is difference between vb script and java script?

JavaScript is just like VB Script, but VB Script is what windows made to try to get rid of JavaScript, but as you can see im sure JavaSript is the winner. They are the same thing pretty much just a little alterations in the code.

### What is the work of compiler in dot net?

It translates the .NET-compatible code (i.e. VB, C#) to MSIL code, then, on demand, the JIT compiler compiles it to machine code.

### Can you make vb in vb?

Yes it is possible, most things are in VB