vb.net计算文本 vb文本框的数字计算
VB.net中多个个文本框之间的计算
呵呵,就当练手了
创新互联公司联系电话:18980820575,为您提供成都网站建设网页设计及定制高端网站建设服务,创新互联公司网页制作领域十年,包括成都公路钻孔机等多个行业拥有多年的网站制作经验,选择创新互联公司,为网站保驾护航!
Add_VB.aspx 代码
%@ Page Language="VB" AutoEventWireup="false" CodeFile="Add_VB.aspx.vb" Inherits="测试代码_Add_VB" %
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head runat="server"
title实现加运算/title
/head
body
form id="form1" runat="server"
div
asp:TextBox ID="TextBox1" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="必须为数字" ValidationExpression="(\d+(\.\d)?){1,1}"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox2" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="必须为数字" ValidationExpression="\d+(\.\d)?"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox3" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="TextBox3" ErrorMessage="必须为数字" ValidationExpression="\d+(\.\d)?"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox4" runat="server" Width="66px"/asp:TextBox
asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="TextBox4" ErrorMessage="必须为数字" ValidationExpression="\d+(\.\d)?"/asp:RegularExpressionValidator
br /
asp:TextBox ID="TextBox5" runat="server" ReadOnly="True"/asp:TextBox
asp:Button ID="Button1" runat="server" Text="求和" Width="78px" /
/div
/form
/body
/html
Add_VB.aspx.vb 代码
Partial Class 测试代码_Add_VB
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Double = TextBox1.Text
Dim b As Double = TextBox2.Text
Dim c As Double = TextBox3.Text
Dim d As Double = TextBox4.Text
TextBox5.Text = a + b + c + d
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If TextBox1.Text = "" Then
TextBox1.Text = 0
End If
If TextBox2.Text = "" Then
TextBox2.Text = 0
End If
If TextBox3.Text = "" Then
TextBox3.Text = 0
End If
If TextBox4.Text = "" Then
TextBox4.Text = 0
End If
End Sub
End Class
vb怎么实现文本多行加减法运算
Dim BDS, JSS, I As Integer
Private Sub Command1_Click()
Dim kkl() As String '取出各行表达式的运算符的数值
ReDim kkl(UBound(BDS))
For I = 0 To UBound(BDS)
kkl(I) = Right(Left(BDS(I), 3), 1) '取出表达式的运算符
Select Case kkl(I)
Case "+"
JSS = Split(BDS(I), "+") '取出运算符二边的数据,存储在 JSS 数组中,下同
Text2.Text = Text2.Text Val(JSS(0)) + Val(JSS(1)) vbCrLf '在文本框2中显示计算结果。数据必须转换为数字数据!,下同
Case "-"
JSS = Split(BDS(I), "-")
Text2.Text = Text2.Text Val(JSS(0)) - Val(JSS(1)) vbCrLf
Case "*"
JSS = Split(BDS(I), "*")
Text2.Text = Text2.Text Val(JSS(0)) * Val(JSS(1)) vbCrLf
Case "/"
JSS = Split(BDS(I), "/")
Text2.Text = Text2.Text Val(JSS(0)) / Val(JSS(1)) vbCrLf
End Select
Next I
End Sub
Private Sub Form_Load()
Text1.Text = Text1.Text "33*33" vbCrLf
Text1.Text = Text1.Text "33+33" vbCrLf
Text1.Text = Text1.Text "33*33" vbCrLf
BDS = Split(Text1.Text, vbCrLf) '将数据存储到 BDS 数组中
End Sub
这个程序符合二位数与二位数的+、-、*、/ 的计算,比较简单。
如何实现VB.NET文字宽度计算
Dim MyGraphics As Graphics = Me.CreateGraphics
'定义使用的字体
Dim Myfont As New Font("宋体", 9)
'获取文本的大小。
Dim Mystring_Size As SizeF = MyGraphics.MeasureString("中", Myfont)
'显示宽和高
MsgBox(Mystring_Size1.Width ":" Mystring_Size1.Height)
我想要在vb.net的环境下实现显示一个输入在文本框的运算表达式的结果,请问该如何实现
简单四则运算转换,查下vbscript的转换字符串为算式就有例子。
简单的解决不了的,自己写逐字分析字符串,然后换成计算。
网站标题:vb.net计算文本 vb文本框的数字计算
地址分享:http://pwwzsj.com/article/doohiog.html