网站首页 > 文章中心 > 其它

vb.net矩阵计算器

作者:小编 更新时间:2023-09-16 17:23:21 浏览量:479人看过

用VB.NET编的计算器程序!

Public Class SimpleCalculator

Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()

MyBase.New()

'该调用是 Windows 窗体设计器所必需的.

InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写处置以清理组件列表.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

MyBase.Dispose(disposing)

'Windows 窗体设计器所必需的

Private components As System.ComponentModel.IContainer

'注意:以下过程是 Windows 窗体设计器所必需的

'可以使用 Windows 窗体设计器修改此过程.

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents Button10 As System.Windows.Forms.Button

Friend WithEvents Button11 As System.Windows.Forms.Button

System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.TextBox1 = New System.Windows.Forms.TextBox

Me.Button1 = New System.Windows.Forms.Button

Me.Button10 = New System.Windows.Forms.Button

Me.Button11 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'Label1

Me.Label1.Name = "Label1"

Me.Label1.TabIndex = 0

Me.Label1.Text = "结果:"

'TextBox1

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.TabIndex = 1

Me.TextBox1.Text = ""

'Button1

Me.Button1.Name = "Button1"

Me.Button1.Text = "清空"

'Button10

Me.Button10.Name = "Button10"

Me.Button10.TabIndex = 11

'Button11

Me.Button11.Name = "Button11"

Me.Button11.Text = "0"

'SimpleCalculator

Me.Controls.Add(Me.Button11)

Me.Controls.Add(Me.Button10)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.TextBox1)

Me.Controls.Add(Me.Label1)

Me.Name = "SimpleCalculator"

Me.Text = "简单计算器"

Me.ResumeLayout(False)

#End Region

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Private Sub TextBox1_TabStopChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim btn As Button '按钮类型的变量

btn = sender '把产生该事件的按钮对象赋值给btn

TextBox1.Text = TextBox1.Text ◆ btn.Text '把该按钮的Text属性值连接到TextBox1中

Dim btn As Button

btn = sender

TextBox1.Text ◆= btn.Text

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

'在文本框的Text属性后连接一个空格、本按钮的Text属性值和一个空格

TextBox1.Text = TextBox1.Text ◆ " " ◆ btn.Text ◆ " "

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = "" '清空文本框

'发生错误转移到标号"ErrorPro"指定的行去执行错误处理程序

On Error GoTo ErrorPro

Dim r As Decimal '保存计算结果的变量

Dim t As String = TextBox1.Text '用于保存文本框中的算术表达式

Dim space As Integer = t.IndexOf(" ") '搜索空格位置,如果没有空格,返回值为0

Dim s1 As String = t.Substring(0, space) '通过取子串方法获得第一个运算数

Dim op As String = t.Substring(space ◆ 1, 1) '通过取子串方法获得运算符

Select Case op

Case Else

MsgBox("输入的运算符有误!")

Exit Sub

End Select

TextBox1.Text = CStr(r) '显示结果

Exit Sub '退出过程

ErrorPro: '错误处理程序块

Select Case Err.Number

MsgBox("算术运算溢出!", , "溢出提示")

TextBox1.Focus()

MsgBox("必须输入运算符和第二个运算数!", , "运算数少")

'其它情况显示错误号和错误原因

End Class

如何用VB.NET编写计算器

简单的说拖出一些控件,设置相应的caption和属性等等,双击每个button控件,进行相应的处理,即可

如何用VB.net制作一个简单的计算器

script language="javascript"

function EnterKeyClick(){

event.returnValue = false;

//你需要执行的函数

}

/script

以上就是土嘎嘎小编为大家整理的vb.net矩阵计算器相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章