用VB做个计算器
我用VB6做的,你参考一下
VB计算器代码:
Dim start As BooleanDim s1#, s2#, s3#Dim sn As StringPrivate Sub Command1_Click()If start = True Then Text1.Text = "1" start = FalseElse Text1.Text = Text1.Text & "1" End IfEnd SubPrivate Sub Command10_Click()Text1.Clear() start = False
End SubPrivate Sub Command11_Click()s1 = Val(Text1.Text)sn = "+"start = TrueEnd SubPrivate Sub Command12_Click()s1 = Val(Text1.Text)sn = "-"start = TrueEnd SubPrivate Sub Command13_Click()s1 = Val(Text1.Text)sn = "*"start = TrueEnd SubPrivate Sub Command14_Click()s1 = Val(Text1.Text)sn = "/"start = TrueEnd SubPrivate Sub Command15_Click()s2 = Val(Text1.Text)If sn = "*" Thens3 = s1 * s2ElseIf sn = "/" Thens3 = s1 / s2start = TrueElseIf sn = "+" Thens3 = s1 + s2start = TrueElseIf sn = "-" Thens3 = s1 - s2start = TrueEnd Ifstart = TrueText1.Text = s3If s3 0 Or sn "" Then Text1.Text = Format(s3, "0.##") End IfEnd SubPrivate Sub Command16_Click()Text1.Text = 0 start = TrueEnd SubPrivate Sub Command17_Click()Text1.Text = Text1.Text & "."
start = FalseEnd SubPrivate Sub Command2_Click()If start = True Then Text1.Text = "2" start = FalseElse Text1.Text = Text1.Text & "2" End IfEnd SubPrivate Sub Command3_Click()If start = True Then Text1.Text = "3" start = FalseElse Text1.Text = Text1.Text & "3" End IfEnd SubPrivate Sub Command4_Click()If start = True Then Text1.Text = "4" start = FalseElse Text1.Text = Text1.Text & "4" End IfEnd SubPrivate Sub Command5_Click()If start = True Then Text1.Text = "5" start = FalseElse Text1.Text = Text1.Text & "5" End IfEnd SubPrivate Sub Command6_Click()If start = True Then Text1.Text = "6" start = FalseElse Text1.Text = Text1.Text & "6" End IfEnd SubPrivate Sub Command7_Click()If start = True Then Text1.Text = "7" start = FalseElse Text1.Text = Text1.Text & "7" End IfEnd SubPrivate Sub Command8_Click()If start = True Then Text1.Text = "8" start = FalseElse Text1.Text = Text1.Text & "8" End IfEnd SubPrivate Sub Command9_Click()If start = True Then Text1.Text = "9" start = FalseElse Text1.Text = Text1.Text & "9" End IfEnd SubPrivate Sub Form_Load()End Sub
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 计算器
{
public partial class MainStrip : Form
{
public MainStrip()
{
InitializeComponent();
}
public string number;
public int OperationType ;//适用于计算的类型,应用数字去控制算法
public double number1,number2 ;
public string Temp;//适用于复制储存中的数据
public double TempData=0;//适用于M等操作的变量
private void Number_0_Click(object sender, EventArgs e)
{
number = number + "0";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
private void Number_1_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "1";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "1";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_2_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "2";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "2";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_3_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "3";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "3";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_4_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "4";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "4";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_5_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "5";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "5";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_6_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "6";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "6";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_7_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "7";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "7";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_8_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "8";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "8";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Number_9_Click(object sender, EventArgs e)
{
if (TextBox.Text == "0")
{
number = "9";
TextBox.Text = Convert.ToString(number);
}
else
{
number = number + "9";
number2 = Convert.ToDouble(number);
TextBox.Text = number;
}
}
private void Button_Plus_Click(object sender, EventArgs e)
{
if (TextBox.TextLength > 0)
{
number1 = Convert.ToDouble(TextBox.Text);
number = "";
OperationType = 1;
TextBox.Text = "";
TextBox.Focus();
}
}
//========================================================================================================
private void Button_Minus_Click(object sender, EventArgs e)
{
if (TextBox.TextLength > 0)
{
number1 = Convert.ToDouble(TextBox.Text);
number = "";
OperationType = 2;
TextBox.Text = "";
TextBox.Focus();
}
}
//========================================================================================================
private void Button_Multiply_Click(object sender, EventArgs e)
{
if (TextBox.TextLength > 0)
{
number1 = Convert.ToDouble(TextBox.Text);
number = "";
OperationType = 3;
TextBox.Text = "";
TextBox.Focus();
}
}
//========================================================================================================
private void Button_Devide_Click(object sender, EventArgs e)
{
if (TextBox.TextLength > 0)
{
number1 = Convert.ToDouble(TextBox.Text);
number = "";
OperationType = 4;
TextBox.Text = "";
TextBox.Focus();
}
}
//========================================================================================================
private void Button_Result_Click(object sender, EventArgs e)
{
switch (OperationType)
{
case 1:
TextBox.Text = Convert.ToString(number1 + Convert.ToDouble(number));
number2 = Convert.ToDouble(TextBox.Text);
break;
case 2:
TextBox.Text = Convert.ToString(number1 - Convert.ToDouble(TextBox.Text));
number2 = Convert.ToDouble(TextBox.Text);
break;
case 3:
TextBox.Text = Convert.ToString(number1 * Convert.ToDouble(TextBox.Text));
number2 = Convert.ToDouble(TextBox.Text);
break;
case 4:
TextBox.Text = Convert.ToString(number1 / Convert.ToDouble(TextBox.Text));
number2 = Convert.ToDouble(TextBox.Text);
break;
}
number = "";
number1 = Convert.ToDouble(TextBox.Text);
}
//========================================================================================================
private void Button_MC_Click(object sender, EventArgs e)
{
if (TextBox.TextLength > 0)
{
number1=Convert.ToDouble(number);
number= Convert.ToString(number1 * number1);
TextBox.Text = number;
number = "";
}
}
//========================================================================================================
private void Button_Clear_Click(object sender, EventArgs e)
{
number = "";
TextBox.Text = "";
}
//========================================================================================================
private void Button_sqrt_Click(object sender, EventArgs e)
{
if (Convert.ToDouble(TextBox.Text) < 0)
{
this.TextBox.Text = "error";
}
else
{
number2 = Convert.ToDouble(TextBox.Text);
number = "";
TextBox.Text = Convert.ToString(System.Math.Sqrt(number2));//写成了一段代码
TextBox.Focus();
}
}
//========================================================================================================
private void Button_Reciprocal_Click(object sender, EventArgs e)
{
if (Convert.ToDouble(TextBox.Text) ==0)
{
this.TextBox.Text = "error";
}
else
{
number2 = Convert.ToDouble(TextBox.Text);
number = "";
TextBox.Text = Convert.ToString(1 / number2);
}
}
//========================================================================================================
private void Button_Spot_Click(object sender, EventArgs e)
{
try
{
number = Convert.ToString(number + ".");
TextBox.Text = Convert.ToString(number + "");
}
catch
{
// TextBox.Text = TextBox.Text;
}
}
//========================================================================================================
private void Backspace_Click(object sender, EventArgs e)
{
if (TextBox.Text == "" || TextBox.Text == "0")
{
TextBox.Text ="";
}
else
{
number1 = Convert.ToDouble(TextBox.Text);
number = Convert.ToString((number1 - number1 % 10) / 10);
TextBox.Text = number;
}
}
//========================================================================================================
private void Button_Percent_Click(object sender, EventArgs e)
{
number = Convert.ToString(Convert.ToDouble(TextBox.Text) / 100);
TextBox.Text = number;
number = "";
}
//========================================================================================================
private void Button_ClearE_Click(object sender, EventArgs e)
{
number = "";
TextBox.Text = number;
}
//========================================================================================================
private void button_Opposide_Click(object sender, EventArgs e)
{
number1 = Convert.ToDouble(TextBox.Text);
TextBox.Text = Convert.ToString(0 - number1);
}
//========================================================================================================
private void Button_MS_Click_1(object sender, EventArgs e)
{
TempData = Convert.ToDouble(TextBox.Text);
this.Button_useless.Text = "M";
}
//========================================================================================================
private void Button_MR_Click_1(object sender, EventArgs e)
{
number=Convert.ToString(TempData);
TextBox.Text = Convert.ToString(number);
}
//========================================================================================================
private void Button_MC_Click_1(object sender, EventArgs e)
{
number = "";
TempData = 0;
this.Button_useless.Text = "";
}
//========================================================================================================
private void Button_Madd_Click(object sender, EventArgs e)
{
TextBox.Text = Convert.ToString(Convert.ToDouble(number1 = TempData + Convert.ToDouble(TextBox.Text)));
this.Button_useless.Text = "M";
}
//========================================================================================================
private void 复制ToolStripMenuItem1_Click(object sender, EventArgs e)
{
{
Temp = TextBox.SelectedText;
}
}
//========================================================================================================
private void 粘贴ToolStripMenuItem1_Click(object sender, EventArgs e)
{
TextBox.Text = Temp;
}
private void 帮助主题ToolStripMenuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show("这是一个仿照windows的计算器应用程序");
}
private void 关于计算器ToolStripMenuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show("计算器---作者:---联系方式QQ:776799386");
}
/* private void 关于计算器ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("计算器/n作者:/n联系方式 QQ 776799386");
}*/
//========================================================================================================
}
}
400分。。。在哪?
Option Explicit
Private Sub Command1_Click()
Text1 = ""
Text2 = ""
Label5.Caption = ""
Text1.SetFocus
Option1.Value = True
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
If Option1.Value = True Then
Label5.Caption = Val(Text1) + Val(Text2)
End If
If Option2.Value = True Then
Label5.Caption = Val(Text1) - Val(Text2)
End If
If Option3.Value = True Then
Label5.Caption = Val(Text1) * Val(Text2)
End If
If Option4.Value = True Then
Label5.Caption = Val(Text1) / Val(Text2)
End If
Command1.SetFocus
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Option1.SetFocus
End If
If IsNumeric(Text1.Text) Then
If (KeyAscii = 45) Then
Option2.Value = True
Text2.SetFocus
ElseIf (KeyAscii = 43) Then
Option1.Value = True
Text2.SetFocus
ElseIf (KeyAscii = 42) Then
Option3.Value = True
Text2.SetFocus
ElseIf (KeyAscii = 47) Then
Option4.Value = True
Text2.SetFocus
End If
ElseIf (Len(Text1.Text) > 0) Then
MsgBox "你输入了不正确格式或字符,请重新输入(你只能输入 0--9十个数字)", vbOKOnly + vbInformation, "注意"
Text1.Text = ""
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If IsNumeric(Text2.Text) Then
ElseIf (Len(Text2.Text) > 0) Then
MsgBox "你输入了不正确格式或字符,请重新输入(你只能输入 0--9十个数字)", vbOKOnly + vbInformation, "注意"
Text2.Text = ""
End If
If KeyAscii = 13 Then
Command3.SetFocus
End If
End Sub
还是你提问还是我回答,你把400的悬赏加上再说!
如何在VB中实现基本的计算器功能?
要使用VB编写一个计算器程序,首先需要打开Visual Basic环境。步骤如下:1. 打开Visual Basic:在开始编写的前提下,打开你的Visual Basic软件。2. 创建UserForm:在软件中,你需要创建一个UserForm,这是计算器界面的基础。通过点击“工具”或“视图”菜单,找到“UserForm”,并创建一个新的空白用户表单。
如何用VB创建的菜单实现一个简易的计算器
在工具箱上单击文本框按钮,在窗体上拖出三个文本框,并将其属性清空。同样再拖三个标签,将第一个的属性设置为数一,第二个设置为数二,第三个设置为结果。这样,我们的主界面就制作完成了。接下来我们开始创建菜单,在窗体上右键单击选择“菜单编辑器”。将菜单标题命名为计算,并将其设置为主菜单。
怎样在VB中实现计算器控件?
这是前面板,计算的时候是数值1(运算)数值2,比如数值1-数值2.运算控件就是用指针滑动杆改的,右键单击-》属性-》文本标签里就能设置,每种运算都有个对一个的数,用这些数就能驱动后台的选择结构来选择运算。不要忘记把数值类型改为整形,也是在属性里面设置,改成u8,或者i8就行了。程序框图如下...
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"End Sub ...
用VB编写一个计算器程序的代码
1、创建控件组的方法首先创建一个命令按钮,调整其大小(觉得合适就行),名称为Command1,Caption 属性为数字 0 ;然后进行“复制”和“粘贴”,当选择“粘贴”时,出现对话框提示已有一个同名控件,询问是否创建控件组,选择“是”后,即创建了一个名为“Command”的控件组。这时,第一个按钮的Index...
excel怎么使用vba制作个人所得税计算器?
excel中使用vba制作个人所得税计算器 1、首先我们打开一个工作样表作为例子。2、打开vba编辑窗口,使用alt+f11组合快捷键,或是使用开发者工具标签下的vb快捷按钮。并插入一个新的模块。3、在模块编辑窗口中输入一个函数代码,代码如下:Function 个人所得税() curP = curP - 1600 '...
vb 怎么编这个计算器的程序,越简单越好
用vb6.0 设置1个Label,16个CommandButton,加减乘除设置为一个控件数组Command1,=设置为一个控件数组Command2,0~9到小数点设置成一个控件数组Command3,各自的Index属性值与对应的数值相同,小数点为10,标签的Caption设为空,16个CommandButton按照界面属性设置Caption 代码是: Dim s(1) As ...
用VB做一个简单的加减乘除的计算器,代码是什么?
我们现在首先要做的就是拉出Label,准备三个Label,把label1,label2,label3,这些改成第一个数、第二个数、结果。我们现在要text也要拉出三个,把了text里面text1、text2、text3全部删掉。我们现在要把command拉出四个,把里面command1-4都给成+-*\/ 现在我们现在要双击+,我们开始进行输入代码 ...
怎么用VB做一个计算器
程序流程: 输入要计算数据——>计算结果——>显示数据 VB的实现: 文本框TextBox控件 表达式 标签Label控件 三、编制程序:(一) 在VB6.0中新建一个标准EXE工程 (二) 建立一个窗体,窗体属性设置如下:名称 = Maths Caption = "数学小工具"(三) 在窗体上添加一个文本框TextBox,用于输入...
用vb设计一个计算器,里面的加减乘除按键的代码怎么写
输入框.text = "" ' 等待下一个数值 select case sender.text ' 根据按下的按钮的文本属性确定你要做什么,这里可以用加减乘除号代替 case "加"操作 = "加"case "减"操作 = "减"case "乘"操作 = "乘"case "除"操作 = "除"end select end sub private sub 计算(byval sender a...
张志小活:[答案] 帮你写了一个,调试通过,不过第5个条件很奇怪啊,这样做出来的计算器是不能连续运算的,每次都要按下等号给出结果,程序在附录中若满意请及时采纳,谢谢
三都水族自治县13544913557: 怎样用VB设计简单计算器 - ?
张志小活: Dim x As String Private Sub Command1_Click() Text1.Text = Text1.Text & "1" End Sub Private Sub Command10_Click() Text1.Text = Text1.Text & "6" End Sub Private Sub Command11_Click() Text1.Text = Text1.Text & "9" End Sub ...
三都水族自治县13544913557: 用VB程序设计一个简单计算器 - ?
张志小活: 界面:text11 2 3 +4 5 6 -7 8 9 *0 = AC /代码:dim newnum as booleandim n1,n2 op as integerprivate sub ac_click()text1.text=""end subprivate sub command1_click(i...
三都水族自治县13544913557: 用vb做一个计算器?
张志小活: 先建立一个新的项目文件,里面包含一个Form1的窗体.然后,添加控件,包括一个Text框(Text1),和17个按钮,这17个按钮使用的名称都是Command1,只是Index属性不同,就好象一个数组,创立一组按钮的方法是,先在窗体上建立一个...
三都水族自治县13544913557: 如何使用VB做个加减乘除的小计算器 - ?
张志小活:[答案] VB计算器,可以做加减乘除运算效果还是不错的,若满意请及时采纳,谢谢
三都水族自治县13544913557: VB制作计算器?
张志小活: Private Sub Command1_Click()a1 = Val(Text1.Text) a3 = Int(a1 / 10)Text3.Text = "" cal = 1a2 = Val(Text2.Text) Select Case calCase 1result = (a2 - (a3 + 1) * 20) / a3If a1 < 4 Then MsgBox "", vbCriticalText1.Text = ""Exit Sub End IfIf a...
三都水族自治县13544913557: vb 制作简易计算器 - ?
张志小活: 初学者的VB计算器 窗体代码如下 Option Explicit Dim blnStratrOperationFlag As Boolean '是否开始运算 Dim lngOperationFlag As Long '运算标志 Dim dblFirstOperationValue As Double '先前的操作数 Private Sub cmdValuedDecimal_Click(Index ...
三都水族自治县13544913557: 我想用vb做一个简单的计算器,那位高手可以指点一下 - ?
张志小活: Private Sub Command1_Click()这是加法,其他的只需把+改为其他的 Dim a, b, c As Integer a = Val(Text1.Text) b = Val(Text2.Text) c = a + b MsgBox c '弹出答案 End Sub
三都水族自治县13544913557: 用VB做一个简单的计算器,该怎么做??
张志小活: val(text1.text)+val(text2.text2) '加 val(text1.text)-val(text2.text2) '减 val(text1.text)*val(text2.text2) '乘 val(text1.text)/val(text2.text2) '除
三都水族自治县13544913557: 用VB2010编写一个简单计算器 - ?
张志小活: 方法/步骤打开VB新建一个EXE.如图画上4个按钮控件表示加减乘除,再画上3个文本控件表示两个数与和数,再画一个标签控件加入“=”号.当然,界面可以自己发挥.画好之后,就可以把控件进行命名,注意是属性栏的Caption项命名,以便运行的时候方便识别.好的,现在可以进行最重要的代码编写啦.双击对应的按钮控件,进入代码编写界面.Text3.Text = Val(Text1.Text) + Val(Text2.Text),其实代码很简单,就这一句只要更换把'+'分别换成'-''*''/'即可.好了,现在可以点击运行或者F5键运行,即可得到第一个简单的计算器程序.