<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 ")
这样还准确一点。
__________________________________________________________________________
我也是菜鸟呵~~
__________________________________________________________________________
偶也素菜鸟呵~~~
__________________________________________________________________________
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 ")
这样还准确一点。
__________________________________________________________________________
我也是菜鸟呵~~
__________________________________________________________________________
偶也素菜鸟呵~~~
__________________________________________________________________________