Use VB to make a calculator, need to use an array, look at the following code, Welcome to find ballast!

Source: Internet
Author: User
Tags integer
Array this is my code, please help me see if there is a problem: (I'm going to use an array as a calculator)
Option Explicit
Dim shu1 as double, shu2 as double ' two number entered
Dim result as Double makes the results of the operation
Dim process, Process0, Process1, Process2, PROCESS3, process4 as Variant ' save number 1 with each operator
Dim judge as Variant ' determines which operator is pressed

Private Sub Command1_Click (Index as Integer) ' 0-9 numeric key
Text1.Text = Text1.Text & Index
Text1.setfocus
End Sub

Private Sub command1_keypress (Index As Integer, KeyAscii as Integer) ' blocks keyboard input, but somehow it doesn't work
KeyAscii = 0
End Sub

Private Sub Command2_Click (Index as Integer) '. ' Key
Text1.Text = Text1.Text & "."
End Sub

Private Sub Command3_Click () ' Backspace key
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left (Text1.Text, Len (Text1.Text)-1)
End Sub

Private Sub Command4_click () ' Clear key
Text1.Text = ""
End Sub

Private Sub Command5_click (Index as Integer) ' do operations, always feel that there is a logical problem
SHU1 = Val (Text1.Text)
Process = SHU1
Text1.Text = ""
If judge = Command5 (0) Then
PROCESS0 = shu1 + Command (0)
ElseIf judge = Command5 (1) Then
Process1 = shu1 + Command5 (1)
ElseIf judge = Command5 (2) Then
Process2 = Shu1 + Command (2)
ElseIf judge = Command5 (3) Then
PROCESS3 = shu1 + Command5 (3)
End If
SHU2 = Val (Text1.Text)
End Sub

Private Sub Command6_click () ' equal sign
result = Process + SHU2
Text1.Text = result
If Process0 Then
result = Shu1 + SHU2
ElseIf Process1 Then
result = Shu1-shu2
ElseIf Process2 Then
result = SHU1 * SHU2
ElseIf PROCESS3 Then
result = Shu1/shu2
End If
End Sub

Private Sub Text1_change ()
If Judge = False Then
SHU2 = Val (Text1.Text)
End If
Text1.setfocus
End Sub




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.