用VB做个简单的计算器

社区服务
高级搜索
猴岛论坛电脑百科用VB做个简单的计算器
发帖 回复
倒序阅读 最近浏览的帖子最近浏览的版块
4个回复

[资源分享]用VB做个简单的计算器

楼层直达
环球旅拍监督者

ZxID:17345571

等级: 元老
傻逼权限狗

举报 只看楼主 使用道具 楼主   发表于: 2012-07-08 0
为了能让一些新手能编译,我将所有代码都发出,只要按要求保存以下代码即可.

以下代码保存为"Form1.frm":

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "计算器"
   ClientHeight    =   3240
   ClientLeft      =   5235
   ClientTop       =   3870
   ClientWidth     =   4620
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   3240
   ScaleWidth      =   4620
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command3
      Caption         =   "about"
      Height          =   400
      Index           =   3
      Left            =   3840
      TabIndex        =   24
      Top             =   2640
      Width           =   615
   End
   Begin VB.CommandButton Command3
      Caption         =   "M"
      Height          =   400
      Index           =   2
      Left            =   3840
      TabIndex        =   23
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command3
      Caption         =   "cls"
      Height          =   400
      Index           =   1
      Left            =   3840
      TabIndex        =   22
      Top             =   1440
      Width           =   615
   End
   Begin VB.CommandButton Command3
      Caption         =   "<--"
      Height          =   400
      Index           =   0
      Left            =   3840
      TabIndex        =   21
      Top             =   840
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "cot"
      Height          =   400
      Index           =   8
      Left            =   3120
      TabIndex        =   20
      Top             =   2640
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "tan"
      Height          =   400
      Index           =   7
      Left            =   3120
      TabIndex        =   19
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "cos"
      Height          =   400
      Index           =   6
      Left            =   3120
      TabIndex        =   18
      Top             =   1440
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "sin"
      Height          =   400
      Index           =   5
      Left            =   3120
      TabIndex        =   17
      Top             =   840
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "="
      Height          =   400
      Index           =   4
      Left            =   1680
      TabIndex        =   16
      Top             =   2640
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "."
      Height          =   400
      Index           =   10
      Left            =   960
      TabIndex        =   15
      Top             =   2640
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "/"
      Height          =   400
      Index           =   3
      Left            =   2400
      TabIndex        =   14
      Top             =   2640
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "*"
      Height          =   400
      Index           =   2
      Left            =   2400
      TabIndex        =   13
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "-"
      Height          =   400
      Index           =   1
      Left            =   2400
      TabIndex        =   12
      Top             =   1440
      Width           =   615
   End
   Begin VB.CommandButton Command2
      Caption         =   "+"
      Height          =   400
      Index           =   0
      Left            =   2400
      TabIndex        =   11
      Top             =   840
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "9"
      Height          =   400
      Index           =   9
      Left            =   1680
      TabIndex        =   10
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "8"
      Height          =   400
      Index           =   8
      Left            =   1680
      TabIndex        =   9
      Top             =   1440
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "7"
      Height          =   400
      Index           =   7
      Left            =   1680
      TabIndex        =   8
      Top             =   840
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "6"
      Height          =   400
      Index           =   6
      Left            =   960
      TabIndex        =   7
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "5"
      Height          =   400
      Index           =   5
      Left            =   960
      TabIndex        =   6
      Top             =   1440
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "4"
      Height          =   400
      Index           =   4
      Left            =   960
      TabIndex        =   5
      Top             =   840
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "3"
      Height          =   400
      Index           =   3
      Left            =   240
      TabIndex        =   4
      Top             =   2040
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "2"
      Height          =   400
      Index           =   2
      Left            =   240
      TabIndex        =   3
      Top             =   1440
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "1"
      Height          =   400
      Index           =   1
      Left            =   240
      TabIndex        =   2
      Top             =   840
      Width           =   615
   End
   Begin VB.CommandButton Command1
      Caption         =   "0"
      Height          =   400
      Index           =   0
      Left            =   240
      TabIndex        =   1
      Top             =   2640
      Width           =   615
   End
   Begin VB.TextBox Text1
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   4215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a As Double        '用于存放第一个数
Dim b As Double        '用于存放第二个数
Dim m As Double        '用于记忆功能
Dim s As Integer       '用于存放运算符号
Dim u As Boolean       '判断记忆功是否用过
Dim ru As Boolean      '用于控制小数点的输入
Dim flag As Boolean    '用以判断是否是一次新的计算
Private Sub Command1_Click(Index As Integer)
If flag = True Then
Text1.Text = ""
flag = False
End If
If Text1.Text = "0" Then
Text1.Text = ""
End If
Select Case Index
Case 0
If Text1.Text <> "" And Text1.Text <> "0" Then
Text1.Text = Text1.Text + "0"
Else
Text1.Text = "0"
End If
Case 10
If ru = False Then
If Text1.Text <> "" Then
Text1.Text = Text1.Text + "."
Else
Text1.Text = "0."
End If
ru = True
End If
Case Else
Text1.Text = Text1.Text + LTrim(Str(Index))
End Select
End Sub

Private Sub Command2_Click(Index As Integer)
If Val(Text1.Text) Then
Select Case Index
Case 0 To 3
a = Val(Text1.Text)
s = Index
flag = True
ru = False
Case 4
b = Val(Text1.Text)
flag = True
ru = False
Select Case s
Case "0"
Text1.Text = a + b
Case "1"
Text1.Text = a - b
Case "2"
Text1.Text = a * b
Case "3"
Text1.Text = a / b
End Select
Case 5
Text1.Text = Sin(Val(Text1.Text))
flag = True
ru = False
Case 6
Text1.Text = Cos(Val(Text1.Text))
flag = True
ru = False
Case 7
Text1.Text = Tan(Val(Text1.Text))
flag = True
ru = False
Case 8
Text1.Text = 1 / Tan((Val(Text1.Text)))
flag = True
ru = False
End Select
Else
MsgBox "输入有误"
Text1.Text = ""
End If
End Sub


Private Sub Command3_Click(Index As Integer)
Select Case Index
Case 0
If Text1.Text <> "" Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
Case 1
Text1.Text = ""
Text1.SetFocus
Case 2
If u = False Then
If Val(Text1.Text) Then
m = Val(Text1.Text)
Else
MsgBox "输入有误"
Text1.Text = ""
u = True
End If
Else
Text1.Text = m
End If
If u = True Then
u = False
Else
u = True
End If
Case 3
MsgBox "本程序由灰色轨迹制作,谢谢使用!QQ:66073692"
End Select
End Sub

Private Sub Form_Load()
flag = False
ru = False
u = False
End Sub

以下代码保存为"MSSCCPRJ.SCC":

[SCC]
SCC=This is a source code control file
[工程1.vbp]
SCC_Project_Name=this project is not under source code control
SCC_Aux_Path=<This is an empty string for the mssccprj.scc file>
以下代码保存为"工程1.vbp":

Type=Exe
Form=Form1.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\system32\stdole2.tlb#OLE Automation
IconForm="Form1"
Startup="Form1"
Command32=""
Name="工程1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="jujumao"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

以下代码保存为"工程1.vbw":

Form1 = 44, 58, 635, 503, C, 22, 29, 684, 568, C
此程序只是作为新手练习控件数组有些用途。
beiwei1937

ZxID:10536036

等级: 少校
其实,很多事情看得通透,不想讲而已。。。
举报 只看该作者 沙发   发表于: 2012-07-08 0
  楼上的妹子不错。
我就是那永远的路人甲…事件记录http://www.dashijian.org/
 Qecluse 

ZxID:8314024

等级: 禁止发言

举报 只看该作者 板凳   发表于: 2012-07-08 0
学过 VB
可是这是要死掉多少脑细胞

楼主留言:

放心吧  人的脑细胞多的很

幻希空

ZxID:17414929

等级: 元老
一片花飞减却春          风飘万点正愁人

举报 只看该作者 地板   发表于: 2012-07-09 0
表示搞C++的飘过

际遇之神

惩罚

看到了凤姐,当场吓晕,花去治疗费DB4

交易区
Alz

ZxID:17763400

等级: 上等兵
举报 只看该作者 4楼  发表于: 2012-07-11 0
- - 在学易语言,求高手赐教 Q649130068
« 返回列表
发帖 回复