呵呵,就當(dāng)練手了
創(chuàng)新互聯(lián)公司聯(lián)系電話:18980820575,為您提供成都網(wǎng)站建設(shè)網(wǎng)頁設(shè)計及定制高端網(wǎng)站建設(shè)服務(wù),創(chuàng)新互聯(lián)公司網(wǎng)頁制作領(lǐng)域十年,包括成都公路鉆孔機等多個行業(yè)擁有多年的網(wǎng)站制作經(jīng)驗,選擇創(chuàng)新互聯(lián)公司,為網(wǎng)站保駕護航!
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實現(xiàn)加運算/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="必須為數(shù)字" 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="必須為數(shù)字" 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="必須為數(shù)字" 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="必須為數(shù)字" 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
Dim?BDS,?JSS,?I?As?Integer
Private?Sub?Command1_Click()
Dim?kkl()?As?String???'取出各行表達(dá)式的運算符的數(shù)值
ReDim?kkl(UBound(BDS))
For?I?=?0?To?UBound(BDS)
kkl(I)?=?Right(Left(BDS(I),?3),?1)???'取出表達(dá)式的運算符
Select?Case?kkl(I)
Case?"+"
JSS?=?Split(BDS(I),?"+")???'取出運算符二邊的數(shù)據(jù),存儲在?JSS?數(shù)組中,下同
Text2.Text?=?Text2.Text??Val(JSS(0))?+?Val(JSS(1))??vbCrLf????'在文本框2中顯示計算結(jié)果。數(shù)據(jù)必須轉(zhuǎn)換為數(shù)字?jǐn)?shù)據(jù)!,下同
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)?'將數(shù)據(jù)存儲到?BDS?數(shù)組中
End?Sub
這個程序符合二位數(shù)與二位數(shù)的+、-、*、/ 的計算,比較簡單。
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)
簡單四則運算轉(zhuǎn)換,查下vbscript的轉(zhuǎn)換字符串為算式就有例子。
簡單的解決不了的,自己寫逐字分析字符串,然后換成計算。
文章名稱:vb.net計算文本 vb文本框的數(shù)字計算
文章出自:http://www.rwnh.cn/article6/doohiog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、搜索引擎優(yōu)化、全網(wǎng)營銷推廣、面包屑導(dǎo)航、定制開發(fā)、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)