This is I write a calculator program, to run there is a problem, hope the great god give directions!
CodePudding user response:
Online code a lot!1. Create the method of control group bai first create a command button, the du whole its size (see fit) zhi, named Command1, Caption attribute dao is 0; And then to "copy" and "paste", when choose "paste", a dialog prompt controls have a same name, asked whether to create the control group, choose "is", which creates a named "Command" of the control group,
At this time, the Index attribute value of the first button default to "0", the second of the Index attribute value is automatically set to "1", and the size is the same as the first button, only need to modify its Caption attribute for the number "1" and drag it to the appropriate location, then continue to use "paste" method to establish other controls the rest of the buttons in the group, a total of 20 button, each a, just drag it to the right place, and modify the corresponding Caption attribute values,
2. The control group the attribute set is as follows:
Write the code
Dim As Single s1 and s2 As Single, ysf As String
'define two single precision number of deposit with the number of variables involved in the operation, a character store operator
Private Sub Command1_Click (Index As an Integer)
Text1. Text=Text1. Text & amp; Command1 (Index). Caption 'to the click event of Command1 connected with the contents of a text box shows the
End Sub
Private Sub Command2_Click ()
Text1. Text=Text1. Text + ", "
If (InStr (Text1. Text, ", ")=1) Then 'first to decimal
Text1. Text=""
End the If
If InStr (Text1. Text, ", ") "Len (Text1. Text) Then prevent two decimal
'Text1. Text=Left
(Text1. Text, Len (Text1. Text) - 1)
End the If
End Sub
Private Sub
Command3_Click ()
S2=Val (Text1. Text) computing
'beginning to addition, subtraction, multiplication, and divisionThe Select Case ysf Case "+"
Text1. Text=s1 + s2
Case ", "
Text1. Text=s1 and s2
Case '*'
Text1. Text s2=s1 *
Case "/"
If s2=0 Then
MsgBox "the denominator is not zero!"
Text1. Text=""
The Else
Text1. Text=s1/s2 End If End the Select
Text1=IIf (Left (Text1. Text, 1)=", ", 0 & amp; Text1. Text, Text1. Text) '
This is very critical, if not the, less than 1, the decimal is 0
End Sub
Private Sub Command4_Click ()
If Text1. Text="" Then" Text is empty end
The Exit Sub
End the If
Text1. Text=Left (Text1. Text, Len (Text1. Text) - 1) 'Text back one
End Sub
Private Sub Command5_Click ()
Text1. Text="" remove the current Text box
'End Sub
Private Sub Command6_Click (Index As an Integer)
S1=Val (Text1. Text) 'will be hidden ysf s1=Command6 (Index). Caption
Text1. Text=""
End Sub
Private Sub Command7_Click ()
If Left (Text1. Text, 1) "" "- "Then judge as a negative number
'Text1. Text="-" & amp; Text1. Text
The Else
Text1. Text=Right (Text1. Text, Len (Text1. Text) - 1)
End the If
End Sub
Private Sub Command8_Click ()
Text1. Text=Text1. Text * Text1. The Text 'square
End Sub
CodePudding user response:
The run up to see where you have any question, put the problematic and error messages posted,