我試圖讓單個文本框(txtRecord)拆分爲6個其他文本框。 (txtField1,txtField2,txtField3,txtField4,txtField5,txtField6)。我想在每個逗號分開。示例輸入:555一些St.,City,State,ZipCode。 我希望每一個分解(555一些聖)將進入txtField1。 (城市)將進入txtField2。 (狀態)將進入txtField3。 (ZipCode)將進入txtField4。我再次需要逗號作爲轉折點。當輸入被拆分時,我需要刪除逗號。我已經讓他們分裂,但如果我沒有每個文本框的信息,它踢了一個錯誤,它也把逗號放入txtFields。附註我有Option Srtict ON。我也知道標籤會更好用,但該項目需要文本框。將文本從輸入拆分爲多個文本框
Private Sub btnBreakApart_Click(sender As Object, e As EventArgs) Handles btnBreakApart.Click
Dim strRecord As String = txtRecord.Text
Dim ArryList() As String = strRecord.Split(CType(",", Char()))
Dim ctrlText As TextBox() = New TextBox() {txtField1, txtField2, txtField3, txtField4, txtField5, txtField6}
'Return txtRecord input box back to white
txtRecord.BackColor = Color.White
'Split data into different text boxes
If txtRecord.Text = "" Then
MessageBox.Show("Null Value Not Allowed")
txtRecord.Focus()
txtRecord.BackColor = Color.Yellow
Else
For x As Integer = 0 To strRecord.Length - 1
ctrlText(x).Text = strRecord(x)
Next
End If
有工具,採空區解析CSV記錄。 – Plutonix
Split之後的ArryList是什麼,可以像strRecord.Split(「,」)'AFAIK一樣完成?什麼是錯誤和哪一行? – topshot
您正在通過strRecord循環 - 「For x As Integer = 0 to strRecord.Length - 1」。你不應該通過ArryList循環嗎? – Mark