1.如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能
如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能
用记事本把这段代码复制过去,然后另存为.frm就可以了VERSION 5.
Begin VB.Form frmMain
Appearance = 0 'Flat
BackColor = &H&
BorderStyle = 3 'Fixed Dialog
Caption = "简单计算器"
ClientHeight =
ClientLeft =
ClientTop =
ClientWidth =
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight =
ScaleWidth =
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command
Caption = "^"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.PictureBox picDisplay
Appearance = 0 'Flat
BackColor = &H&
ForeColor = &H&
Height =
Left =
ScaleHeight =
ScaleWidth =
TabIndex =
Top =
Width =
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BorderStyle = 0 'None
Height =
Left =
Locked = -1 'True
TabIndex =
Top = 0
Width =
End
Begin VB.Label lblOperation
Appearance = 0 'Flat
BackColor = &H&
ForeColor = &H&
Height =
Left =
TabIndex =
Top = 0
Width =
End
End
Begin VB.CommandButton Command9
Caption = "退格"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command8
Caption = "清零"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton cmdDot
Caption = "."
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command7
Caption = "Sqrt"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command6
Caption = "="
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command5
Caption = "/"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command4
Caption = "*"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command3
Caption = "-"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command2
Caption = "+"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "9"
Height =
Index = 9
Left =
TabIndex = 9
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "8"
Height =
Index = 8
Left =
TabIndex = 8
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "7"
Height =
Index = 7
Left =
TabIndex = 7
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "6"
Height =
Index = 6
Left =
TabIndex = 6
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "5"
Height =
Index = 5
Left =
TabIndex = 5
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "4"
Height =
Index = 4
Left =
TabIndex = 4
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "3"
Height =
Index = 3
Left =
TabIndex = 3
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "2"
Height =
Index = 2
Left =
TabIndex = 2
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "1"
Height =
Index = 1
Left =
TabIndex = 1
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "0"
Height =
Index = 0
Left =
TabIndex = 0
Top =
Width =
End
End
Attribute VB_Name = "frmmain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Data As Double
Private lOperation As Long
Private fClear As Boolean
Private Sub cmdDot_Click()
If InStr(1,源码源码蜂鸟摄影论坛源码 Text1.Text, ".") <= 0 Then Text1.Text = Text1.Text & "."
End Sub
Private Sub Command1_Click(Index As Integer)
If fClear = True Then Text1.Text = "": fClear = False
Text1.Text = Text1.Text & Index
End Sub
Private Sub Command_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 5
lblOperation.Caption = "^"
End Sub
Private Sub Command2_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 1
lblOperation.Caption = "+"
End Sub
Private Sub Command3_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 2
lblOperation.Caption = "-"
End Sub
Private Sub Command4_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 3
lblOperation.Caption = "*"
End Sub
Private Sub Command5_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 4
lblOperation.Caption = "/"
End Sub
Private Sub Command6_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command7_Click()
If Val(Text1.Text) <= 0 Then MsgBox "开方数大于等于0"
Text1.Text = Sqr(Val(Text1.Text))
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command8_Click()
Text1.Text = ""
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command9_Click()
If Len(Text1.Text) > 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0"): Command1_Click 0
Case Asc("1"): Command1_Click 1
Case Asc("2"): Command1_Click 2
Case Asc("3"): Command1_Click 3
Case Asc("4"): Command1_Click 5
Case Asc("5"): Command1_Click 4
Case Asc("6"): Command1_Click 6
Case Asc("7"): Command1_Click 7
Case Asc("8"): Command1_Click 8
Case Asc("9"): Command1_Click 9
Case Asc("."): cmdDot_Click
Case Asc("+"): Command2_Click
Case Asc("-"): Command3_Click
Case Asc("*"): Command4_Click
Case Asc("/"): Command5_Click
Case Asc("^"): Command_Click
Case Asc("s"): Command7_Click
Case Asc("S"): Command7_Click
Case vbKeyBack: Command9_Click
Case Asc("`"): Command8_Click
Case Asc("="): Command6_Click
Case : Command6_Click
End Select
KeyAscii = 0
End Sub
2024-11-25 02:15444人浏览
2024-11-25 02:002389人浏览
2024-11-25 01:422031人浏览
2024-11-25 01:092201人浏览
2024-11-25 00:3173人浏览
2024-11-25 00:02313人浏览
1.关于一款开源远程控制软件(gh0st)的源码分析一)2.使用IDEA调试远程Java代码关于一款开源远程控制软件(gh0st)的源码分析一) gh0st软件专为远程控制设计,支持远程文件传输、
1.通达信“游资智能分时抓板”主指标公式--抓板利器2.通达信资金流分时主图指标公式源码3.求高手写个通达信当天开盘价在分时图上自动画线的分时主图指标?谢谢!4.怎么把指标添加到通达信分时图主图里面通
1.电影《幸运贩卖机》定档,这部影片主要讲述的是什么故事?2.梦想贩卖机香水有毒吗?电影《幸运贩卖机》定档,这部影片主要讲述的是什么故事? 喻恩泰之所以同意出演《幸运贩卖机》这部**,主要是因为这