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

VB.NET源码-156个实用实例哦…… <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
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 ")

这样还准确一点。
__________________________________________________________________________
我也是菜鸟呵~~
__________________________________________________________________________
偶也素菜鸟呵~~~
__________________________________________________________________________
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值