[VB.NET]VB.NET里 string怎么转换为textbox? 菜鸟提问 ^^:;;

VB.NET里 string怎么转换为textBox? 菜鸟提问 ^^:;; 我的画面有142个textBox ,而且textBox 的名字是 txt1,txt2.....txt142 我想用for 语句来循环它并取得他们的值 可是我怎么也找不到vb.net 2003里 让string转换为textBox 方法 大家帮忙下 这里谢过了~~ 我是菜鸟 希望各位大虾写的详细点 __________________________________________________________________________ dim s as string dim i as short for i = 1 to 142 s = "txt " & i for each ctrl as control in me.controls if ctrl.getType.name = "TextBox " then if ctrl.name = s then ctrl.text = " " end if end if next next __________________________________________________________________________ 其实最好是用控件数组来做,像您这样做的话会麻烦一点。 用这个可以把内容存入一个字符串数组中: Public Class Form1 Private Sub Button1_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles Button1.Click Dim s(142) As String For Each ctrl As Control In Me.Controls If TypeOf ctrl Is TextBox Then Dim i As String = ctrl.Name.Substring(3) If ctrl.Name.Contains( "txt ") And IsNumeric(i) Then Dim index As Integer = Int32.Parse(i) s(index) = ctrl.Text End If End If Next MsgBox(s(1) & s(2) & s(3)) End Sub End Class __________________________________________________________________________ magicbacon(Cannot help coding) 您好~ 我想问下在你的代码当中 If ctrl.Name.Contains( "txt ") And IsNumeric(i) Then 这里的 Contains 是什么意思? 我输入代码的时候用不了 Contains 这个小编 菜鸟一个 多多包含 ^^:;;;; __________________________________________________________________________ 这个是为了确定控件名中包含 "txt ",防止读取到其他TextBox的值,您用的是2003吧?那么可以用 InStr(strl.Name,"txt ") = 1 来代替 ctrl.Name.Contains( "txt ") 这样还准确一点。 __________________________________________________________________________ 我也是菜鸟呵~~ __________________________________________________________________________ 偶也素菜鸟呵~~~ __________________________________________________________________________

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...