Dim Str1 As String
Dim str2 As String
dim i as integer
Dim myTb As TextBox
myTb = Controls("textbox" & i)
Str1 = "_"
Str2 = DataGridView1.Rows(7).Cells(7).Value '字符串 str2中有多个"_"
'想通过截取字符串str2的内容,赋值于myTb.text
'截取字符串要求是"_"之前的内容,例如 abc_defg_1_dd (但此处未知有多少个"_", "a"为起始值)
'分别将 abc赋值于textbox1, defg赋值于textbox2, 1赋值于textbox3, ...
"因此处有三个变量,即 "_"的个数,"_"在str2中的位置,textbox的数量
"望提供排序代码
vb不会,不过你这种只需要Split下,然后遍历拆分的数据,获取控件后赋值就行了
Str2 = DataGridView1.Rows(7).Cells(7).Value '字符串 str2中有多个"_"
Dim arr = Split(Str, "_")
Dim l = arr.Length
For i = 0 To l
myTb = Controls("textbox" & i)'还要注意textbox的下标起始
'这里要判断myTb是否为null,要不数组数据长度大于你textbox的数量会报错,不会vb,楼主自己可以加代码。如果是C#用 if(myTb!=null)
myTb.Text=arr (i)
Next
~
i = 0
c = InStr(Str2,Str1)
Do while c > 0
s(i) = Left(Str2, c - 1)
i = i + 1
Str2 = Right(Str2, Len(Str2) - c)
c = InStr(Str2,Str1)
Loop
s(i) = Str2
Dim a, x, s As Integer
Dim values = Split(DataGridView1.Rows(n - 1).Cells(7).Value, "_")
Dim myTb As TextBox
'x = Len(str2)
'a = (Len(str2) - Len(Replace(str2, Str1, ""))) / Len(Str1)
For s = 1 To values.Length
myTb = TabControl1.TabPages(0).Controls("TextBox" & s)
myTb.Text = values(s - 1)
Next
End If
End If
'为后来人能有个参考
'VB.NET中Controls,前要去父项指明(如:TabControl1.TabPages(0).Controls("TextBox" & s))
'结贴