2016-11-21 52 views
0

我有5个文本框,并且在每个文本框中都必须写入值以及所有要存储到数组中的值。 这是我做如何在数组中存储多个文本框的值

Dim arrayNames() As String = {CDec(txtName1.Text), CDec(txtName2.Text), CDec(txtName3.Text), CDec(txtName4.Text), CDec(txtName5.Text)} 
+2

试试:'昏暗arrayNames作为变体:arrayNames =阵列(CDEC(txtName1.Text ),CDec(txtName2.Text),CDec(txtName3.Text),CDec(txtName4.Text),CDec(txtName5.Text))' –

+0

您有没有机会尝试解决方案? –

回答

0

使用Array功能与一组已知的项目,如维克多注意到点评:

Dim myArray() As String 
myArray = Array(TextBox1.Value, TextBox2.Value, TextBox3.Value) 

如果您需要动态添加到阵列中,然后就可以使用ReDim Preserve语句,它调整大小的阵列,并保留现有值:

Dim myArray() As String 
myArray = Array(TextBox1.Value, TextBox2.Value, TextBox3.Value) 

'later, add another element to the array: 
ReDim Preserve myArray(Ubound(myArray)+1) 
myArray(UBound(myArray)) = TextBox4.Value 
相关问题