求VB简易计算器的代码?

作者&投稿:宣轮 (若有异议请与网页底部的电邮联系)
求VB简易计算器的代码~

Dim dflag As Integer
Dim I As Integer
Dim opnre As Integer
Dim prev As Double
Dim oflag As Integer
Dim ind As Integer
Dim soundbz As Boolean
Dim ProgramPath As String
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal Cx As Long, ByVal Cy As Long, ByVal wFlags As Long) As Long
Public Sub SetOnTop(ByVal IsOnTop As Integer)
Dim rtn As Long
If IsOnTop = 1 Then
'将窗口置于最上
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
Else
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
End If
End Sub
Private Sub Check1_Click()
If Check1.Value = 1 Then
SetOnTop 1
Else
SetOnTop 0
End If
End Sub
Private Sub Command1_Click(Index As Integer)
text1 = Trim(text1)
If Len(text1) > 20 Then
Beep
Exit Sub
End If
soundbz = False
MMControl1.Command = "Close"

MMControl1.FileName = ProgramPath & "/声音文件/" & Index & ".wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"

If ind = 4 Then
prev = 0
text1.Caption = " "
ind = 0
End If
opnre = 0
If oflag = 0 Then
text1.Caption = " "
End If
oflag = 1
If Command1(Index).Caption "." Then
If text1.Caption " 0" Then
text1.Caption = text1.Caption & Command1(Index).Caption
Text = Mid(text1, 1, 1)
If Text = "." Then
text1 = "0" & text1
End If
Else
text1.Caption = " " & Command1(Index).Caption
End If
Else
If dflag = 0 Then
text1.Caption = text1.Caption & "."

dflag = 1
Else
Command6.SetFocus
Exit Sub
End If
End If
Command6.SetFocus
End Sub
Private Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0

End Sub
Private Sub Command2_Click(Index As Integer)
soundbz = False
MMControl1.Command = "Close"
If Index = 0 Then MMControl1.FileName = ProgramPath & "/声音文件/加.wav"
If Index = 1 Then MMControl1.FileName = ProgramPath & "/声音文件/减.wav"
If Index = 3 Then MMControl1.FileName = ProgramPath & "/声音文件/乘.wav"
If Index = 2 Then MMControl1.FileName = ProgramPath & "/声音文件/除.wav"
If Index = 4 Then
MMControl1.FileName = ProgramPath & "/声音文件/等于.wav"
soundbz = True
End If
MMControl1.Command = "Open"
MMControl1.Command = "Play"
If opnre = 0 Or Index = 4 Then
If ind = 0 Then
prev = prev + Val(text1.Caption)
ElseIf ind = 1 Then
prev = prev - Val(text1.Caption)
ElseIf ind = 2 Then
If Val(text1.Caption) = 0 Then
text1 = "错误"
Beep
Command6.SetFocus
Exit Sub
Else
prev = prev / Val(text1.Caption)
End If
ElseIf ind = 3 Then
prev = prev * Val(text1.Caption)
End If
text1.Caption = Str(prev)
oflag = 0
End If
opnre = 1
ind = Index
dflag = 0

Command6.SetFocus
If Index = 4 Then
If Option1.Value = True Then text1 = Trim(Round(text1, 2))
If Option2.Value = True Then text1 = Trim(Round(text1, 3))
If Option3.Value = True Then text1 = Trim(Round(text1, 4))
If Option4.Value = True Then text1 = Trim(text1)
If text1 0 Then
Text = Mid(text1, 1, 1)
If Text = "." Then
text1 = "0" & text1
End If
End If
ls = Len(text1)
If ls 0 Then
For I = 1 To ls
t = Mid(text1, I, 1)
DoEvents
Do While (MMControl1.Mode 525) And soundbz

DoEvents
Loop
MMControl1.Command = "Close"
If t "." Then
If t = "-" Then
MMControl1.FileName = ProgramPath & "/声音文件/负.wav"
Else
MMControl1.FileName = ProgramPath & "/声音文件/" & t & ".wav"
End If
Else
MMControl1.FileName = ProgramPath & "/声音文件/10.wav"

End If
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Next I
End If
End If
End Sub
Private Sub Command2_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command3_Click()
soundbz = False
MMControl1.Command = "Close"
MMControl1.FileName = ProgramPath & "/声音文件/归零.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
text1.Caption = " 0"
Command6.SetFocus
End Sub
Private Sub Command3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command4_Click()
soundbz = False
MMControl1.Command = "Close"
MMControl1.FileName = ProgramPath & "/声音文件/清除.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"

dflag = 0
prev = 0
oflag = 0
ind = 0
opnre = 0
text1.Caption = " 0"
Command6.SetFocus
End Sub
Private Sub Command4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command5_Click()
soundbz = False
SaveSetting App.EXEName, "保留", "n1", Option1.Value
SaveSetting App.EXEName, "保留", "n2", Option2.Value
SaveSetting App.EXEName, "保留", "n3", Option3.Value
SaveSetting App.EXEName, "保留", "n4", Option4.Value
SaveSetting App.EXEName, "置顶", "yorn", Check1.Value
' MMControl1.Command = "Close"
Unload Me
End Sub
Private Sub Command5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command6_Click()
Command2_Click (4)
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If text1 = "错误!" Then
Command4_Click
End If
If KeyAscii = Asc(".") Then
I = 10
Command1_Click (I)
ElseIf KeyAscii = Asc("0") Then
I = 0
Command1_Click (I)
ElseIf KeyAscii = Asc("1") Then
I = 1
Command1_Click (I)
ElseIf KeyAscii = Asc("2") Then
I = 2
Command1_Click (I)
ElseIf KeyAscii = Asc("3") Then
I = 3
Command1_Click (I)
ElseIf KeyAscii = Asc("4") Then
I = 4
Command1_Click (I)
ElseIf KeyAscii = Asc("5") Then
I = 5
Command1_Click (I)
ElseIf KeyAscii = Asc("6") Then
I = 6
Command1_Click (I)
ElseIf KeyAscii = Asc("7") Then
I = 7
Command1_Click (I)
ElseIf KeyAscii = Asc("8") Then
I = 8
Command1_Click (I)
ElseIf KeyAscii = Asc("9") Then
I = 9
Command1_Click (I)
ElseIf KeyAscii = Asc("0") Then
I = 0
Command1_Click (I)
ElseIf KeyAscii = Asc("+") Then
I = 0
Command2_Click (I)
ElseIf KeyAscii = Asc("+") Then
I = 0
Command2_Click (I)
ElseIf KeyAscii = Asc("-") Then
I = 1
Command2_Click (I)
ElseIf KeyAscii = Asc("/") Then
I = 2
Command2_Click (I)
ElseIf KeyAscii = Asc("*") Then
I = 3
Command2_Click (I)
ElseIf KeyAscii = Asc("=") Or KeyAscii = 13 Then
I = 4
Command2_Click (I)
ElseIf KeyAscii = Asc("c") Or KeyAscii = Asc("C") Or KeyAscii = 27 Then
Command4_Click
ElseIf KeyAscii = Asc("d") Or KeyAscii = Asc("D") Then
Command3_Click
End If
End Sub
Private Sub Form_Load()
If App.PrevInstance = True Then
Unload Me
MsgBox "程序正在运行", 64, "提示"
End
End If
soundbz = True
dflag = 0
prev = 0
oflag = 0
ind = 0
opnre = 0
Clipboard.Clear
MMControl1.DeviceType = "WaveAudio"
ProgramPath = App.Path
Option1.Value = GetSetting(App.EXEName, "保留", "n1", True)
Option2.Value = GetSetting(App.EXEName, "保留", "n2", False)
Option3.Value = GetSetting(App.EXEName, "保留", "n3", False)
Option4.Value = GetSetting(App.EXEName, "保留", "n4", False)
Check1.Value = GetSetting(App.EXEName, "置顶", "yorn", 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
MMControl1.Command = "Close"
End
End Sub

以上的回答这么麻烦,还让人活吗?只需如此:
涉及控件:text,com1,com2三种
属性设置:无
命令如下:
通用命令
Option Explicit
Dim v As Boolean
Dim s As Integer
Dim x As Double
Dim y As Double
按钮一的命令
Private Sub Command1_Click(Index As Integer)
If Form1.Tag = "s" Then
If Index = 10 Then
Text1.Text = "0"
Else
Text1.Text = Command1(Index).Caption
End If
Form1.Tag = ""
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
End Sub
按钮二的命令
Private Sub Command2_Click(Index As Integer)
Form1.Tag = "s"
If v Then
x = Val(Text1.Text)
v = Not v
Else
y = Val(Text1.Text)
Select Case s
Case 0
Text1.Text = x + y
Case 1
Text1.Text = x - y
Case 2
Text1.Text = x * y
Case 3
If y 0 Then
Text1.Text = x / y
Else
MsgBox ("不能以0为除数")
Text1.Text = x
v = False
End If
Case 4
y = 0
v = False
End Select
x = Val(Text1.Text)
End If
s = Index
End Sub

代码是:码

跪求高人给代码!!!

我有更好回答

匿名用户

推荐于 2016-11-11

Private Sub Command1_Click()

Select Case Text2.Text

Case "+"

Text4.Text = Str(Val(Text1.Text) + Val(Text3.Text))

Case "-"

Text4.Text = Str(Val(Text1.Text) - Val(Text3.Text))

Case "*"

Text4.Text = Str(Val(Text1.Text) * Val(Text3.Text))



Dim OperatorState As Integer
Dim data1 As Integer
Dim data2 As Integer
Dim data3 As Integer
Dim result As Integer
Private Sub Command1_Click()
Text1.Text = "7"
End Sub
Private Sub Command10_Click()
Text1.Text = "6"
End Sub
Private Sub Command11_Click()
Text1.Text = "3"
End Sub
Private Sub Command12_Click()
Text1.Text = ""
End Sub
Private Sub Command13_Click()
data1 = Val(Text1.Text)
OperatorState = 1
Text1.Text = ""
End Sub
Private Sub Command14_Click()
data1 = Val(Text1.Text)
OperatorState = 2
Text1.Text = Text1.Text + ""
End Sub
Private Sub Command15_Click()
data1 = Val(Text1.Text)
OperatorState = 3
Text1.Text = Text1.Text + ""
End Sub
Private Sub Command16_Click()
data1 = Val(Text1.Text)
OperatorState = 4
Text1.Text = Text1.Text + ""
End Sub
Private Sub Command2_Click()
Text1.Text = "4"
End Sub
Private Sub Command3_Click()
Text1.Text = "1"
End Sub
Private Sub Command4_Click()
Text1.Text = "0"
End Sub
Private Sub Command5_Click()
Text1.Text = "8"
End Sub
Private Sub Command9_Click()
Text1.Text = "9"
End Sub
Private Sub Command6_Click()

Text1.Text = "5"
End Sub
Private Sub Command7_Click()
Text1.Text = "2"
End Sub
Private Sub Command8_Click()
data2 = Val(Text1.Text)
If (OperatorState = 1) Then
result = data1 + data2
labvarious = labvarious & Text1.Text
End If
If (OperatorState = 2) Then
result = data1 - data2
End If
If (OperatorState = 3) Then
result = data1 * data2
End If
If (OperatorState = 4) Then
result = data1 / data2
End If
Text1.Text = Str(result)
End Sub


vb:简易计算器(加减乘除)代码
代码如下:Dim t, t1 As Integer Dim x, y As Double Public Sub com()x = Val(l1.Caption)Select Case t1 Case Is = 1: y = y + x Case Is = 2: y = y - x Case Is = 3: y = y * x Case Is = 4: y = y \/ x End Select t1 = 0 t = 0 l1.Caption = "0"...

VB简易计算器代码怎么写
Dim a(100) As Double Dim n& Dim Plus As Boolean Dim yunsuan(100) As Integer '---这里增加 Dim a100 As Double Private Sub cmd1_Click()If Plus = True Then Plus = False Text1.Text = "1"Else Text1.Text = Text1.Text & "1"End If End Sub Private Sub cmd2_Click()If...

用VB编写一个计算器程序的代码
1、创建控件组的方法首先创建一个命令按钮,调整其大小(觉得合适就行),名称为Command1,Caption 属性为数字 0 ;然后进行“复制”和“粘贴”,当选择“粘贴”时,出现对话框提示已有一个同名控件,询问是否创建控件组,选择“是”后,即创建了一个名为“Command”的控件组。这时,第一个按钮的Index...

简易计算器的VB代码解释(要求比较详细,满意后再追加分数)
Dim FuhaoZhuangtai As String Dim FirstNumber, NumbumBuf As Double Private Sub Command1_Click(Index As Integer) '0到9 ch = Format(Index, "0") '原来使用val函数是错误的!那个是把字符串转换成数值。本来要使用str函数,但他的结果总是有数字前面一位空格,所以使用这个了。If Text1.Te...

用VB做一个简单的加减乘除的计算器,代码是什么?
我们现在首先要做的就是拉出Label,准备三个Label,把label1,label2,label3,这些改成第一个数、第二个数、结果。我们现在要text也要拉出三个,把了text里面text1、text2、text3全部删掉。我们现在要把command拉出四个,把里面command1-4都给成+-*\/ 现在我们现在要双击+,我们开始进行输入代码 ...

在VB中计算器的代码(要求0到9的加减乘除运算)
'根据你的要求改了一下:'最简单的计算器(实现0到9的加减乘除运算)'1、添加Command1控件数组0~14 '2、设置Command1的Caption属性:'Command1(0~9) "0~9"'Command1(10~13) "+、-、*、\/"'Command1(14) "="'3、添加Text1控件 '排列好以上控件 Option Explicit Dim TTemp1, TTemp2 As ...

vb 怎么编这个计算器的程序,越简单越好
用vb6.0 设置1个Label,16个CommandButton,加减乘除设置为一个控件数组Command1,=设置为一个控件数组Command2,0~9到小数点设置成一个控件数组Command3,各自的Index属性值与对应的数值相同,小数点为10,标签的Caption设为空,16个CommandButton按照界面属性设置Caption 代码是: Dim s(1) As ...

关于VB制作计算器代码
我也是刚学会的,太简单!Dim cleardisplay As Boolean Dim operand1 As Double Dim operand2 As Double Dim operator As String Private Sub Command1_Click(Index As Integer) '控件数组command1(index),数字0到9 If cleardisplay Then Text1.Text = ""cleardisplay = False End If If Len(Text1...

vb编辑简单计算器的代码
using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1(){ InitializeComponent();} double x, y;int i;private void ...

vb计算器源代码
Private Const opAdd = 1 Private Const opSubtract = 2 Private Const opMultiply = 3 Private Const opDivide = 4 Private Operator As Integer Private NewEntry As Boolean '删除最后的字符 Private Sub DeleteCharacter()Dim txt As String Dim min_len As Integer txt = txtDisplay.Text If ...

涵江区19442484447: 求VB简易计算器代码 -
空类立环: 建立14个按钮,按钮的名字都要Command1,设置Index属性,0~9分别对应数字0~9,10为小数点,11为等号,12~14分别对应+、-、*和/. 2、输入如下代码: Dim Num1, Num2 As Single Dim StrNum1, StrNum2 As String Dim FirstNum As ...

涵江区19442484447: vb简单计算器的代码是什么?
空类立环: 需要3个文本框 第一文本框保存第一个数字 第二个文本框保存第二个数字 第三个文本框保存结果 然后四个命令按钮 作用是 加减乘除 所以代码如下 private sub command1_click() text3.text=val(text1.text)+val(text2.text) end sub 一次类推 private sub...

涵江区19442484447: 求VB简易计算器的代码 -
空类立环: 以上的回答这么麻烦,还让人活吗?只需如此:涉及控件:text,com1,com2三种属性设置:无命令如下:通用命令Option ExplicitDim v As BooleanDim s As IntegerDim x As DoubleDim y As Double按...

涵江区19442484447: 求一个VB计算器代码 -
空类立环: 我是刚刚学VB的,只会做1个简单的,但是拥有+ - * /: Private Sub Command1_Click() Label1.Caption ="+" text3.text=val(text1.text) + val (text2.text) END subPrivate Sub Command2_Click() Label1.Caption ="-" text3.text=val(text...

涵江区19442484447: VB高手进,求一个简单计算器的VB代码 -
空类立环: 这是刚看VB的时候写的一个简易计算器,可以看看Dim Num1, Num2 As SingleDim StrNum1, StrNum2 As StringDim FirstNum As Boolean '判断是否是数字开头Dim PointFlag As Boolean '判断是否已有小数点Dim Runsign As Integer '储存运算符...

涵江区19442484447: VB6.0中编辑一个简单的计算器的代码 -
空类立环: 在加法的按钮框输入 text3.text=val(text1.text)+val(text2.text) 在清除的按框输入 text3.text="" text2.text="" text1.text+=""

涵江区19442484447: 求VB代码:设计一个简单计算器. -
空类立环: 我写的 一个简单的代码, Public h As Integer Public a As Single Public k As Integer Private Sub Command1_Click(Index As Integer) x = Index Select Case x Case 0 If h = 1 Then Text1.Text = "" h = 0 Text1.Text = Text1.Text + "0" Case 1 If h = ...

涵江区19442484447: VB制作计算器的代码 -
空类立环: Option Explicit Dim Op1, Op2 ' 预先输入操作数.Dim DecimalFlag As Integer ' 小数点存在吗?Dim NumOps As Integer ' 操作数个数.Dim LastInput ' 指示上一次按键事件的类型.Dim OpFlag ' 指示未完成的操作.Dim TempReadout ' C ...

涵江区19442484447: 求简单VB计算器程序代码
空类立环: 楼上的,他说他刚入门,你用“If IsNumeric(Trim(Text1.Text)) = True Then StrInt = Trim(Text1.Text) ' 稍微复杂了点了. 我给一段代码吧: Private Sub Command1_Click() If Val(Text1) > 0 And Val(Text1) < 100 Then Text2.Text = (Val(Text1) - 60) / 10 + 1 Else MsgBox "请输入正确数值,否则无效", vbOKOnly + vbExclamation, "警告" End If End Sub

涵江区19442484447: 用VB设计个简单计算器,个按钮的代码怎么编写啊?急 -
空类立环: Dim v As Boolean '是否第1次按运算符 Dim s As String '存放上次按的运算符 Dim x As Double '存放第1个操作数 Dim y As Double '存放第2个操作数 Private Sub Command2_Click() 'ok at 11-10-23 +Call JiSuan("+") End Sub Private Sub ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网