你可以在窗体上加入一个空间数组
Private Sub Text1_KeyPress(index as integer, KeyAscii As Integer)
dim str() as string
redim str(0)
dim bool as boolean
bool=true
if keyascii=13 then
if bool=true then
str(0)=cstr(text1.text)
bool=false
else
redim preserve str(ubound(str)+1)
str(ubound(str))=text1.text
end if
end if
end if
End Sub
Private Sub Command1_Click() '显示录入数据
Dim I As Long
For I = 1 To X.Count
Debug.Print X(I)
Next
End Sub
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) '将录入数据加入集合,清空文本框
If KeyCode = vbKeyReturn And Text1.Text <> "" Then X.Add Text1.Text: Text1.Text = ""
End Sub
'一个textbox,一个按钮:
Option Explicit
Dim i As Long
Dim arrstr() As String
'测试输出
Private Sub Command1_Click()
Dim j As Long
For j = 0 To UBound(arrstr)
Debug.Print arrstr(j)
Next
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
ReDim Preserve arrstr(i)
arrstr(i) = Text1.Text
i = i + 1
Text1.Text = ""
End If
End Sub