我正在使用一个模块来保存重复的代码,但我需要传入一个字段作为可以更改的参数。我使用Form1.controls(variableName & ".text")
来完成文本框的相同操作,但它不适用于字段,因为它们不是控件。这是我用于文本框的代码:
Public Sub fillTextBox(table As DataTable, column As String, value As String, txtNum As Integer)
For i As Integer = 0 To table.Rows.Count() - 1
If table.Rows(i)(column) = value Then
Form1.Controls("Text" & (txtNum).ToString()).Text = table.Rows(i)("VALUE")
End If
Next
End Sub
这就是我想使用Form1中的字段的地方:
Public Sub getData(table As DataTable, column As String, value As String, destination As String, bError As String)
For i As Integer = 0 To table.Rows.Count() - 1
If table.Rows(i)(column) = value Then
Form1.Controls(destination) = table.Rows(i)(column)
Form1.found = True
Exit For
End If
Next
Form1.Controls(bError) = True
End If
Form1.found = False
End Sub
“destination”和“bError”是传递给函数的字段,但它们将是不同的字段,具体取决于正在使用的表和填写的字段。