vb.net计算文本框 vb统计字符个数

VB.NET中,如何获得文本框中可见区域的首行的行号?可先计算出文本框TextBox1中的总行数 , 然后在行号框TextBox2中填上从1到总行数的行号 。
再用API函数GetScrollPos分别获得文本框和行号框当前行号 , 最后再使用API函数SendMessage使行号框的行号滚动到对应的行数 。
因为文本框的滚动条没有滚动事件,可以暂时使用一个Timer定时刷新,虽然方法笨了点,但暂时只能这么用了
代码如下:
Private Declare Function GetScrollPos Lib "user32" (ByVal handle As IntPtr, ByVal nbar As Integer) As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a as integer
a = GetScrollPos(TextBox1.Handle, 1)
Dim b as integer
b = GetScrollPos(TextBox2.Handle, 1)
SendMessage(TextBox2.Handle, HB6, 0, a-b)
End Sub
VB.net中多个个文本框之间的计算呵呵,就当练手了
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.net的环境下实现显示一个输入在文本框的运算表达式的结果,请问该如何实现简单四则运算转换,查下vbscript的转换字符串为算式就有例子 。
简单的解决不了的,自己写逐字分析字符串,然后换成计算 。

推荐阅读