我在文本框中有这样的数据:
我想在listview中将3种类型的数据拆分为3个coloums。我知道如何使用这种类型的代码按字符分割数据:
Private Sub Command1_Click()
Dim a As String
Dim b As String
Dim c As String
Dim i As Long
Dim sLines() As String
Dim sValues() As String
sLines() = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(sLines)
If sLines(i) > vbNullString Then ' skip for empty line
sValues() = Split(sLines(i), ".")
a = sValues(0) & vbCrLf
b = sValues(1) & vbCrLf
c = sValues(2) & vbCrLf
Set List = ListView1.ListItems.Add(, , a)
ListView1.ListItems.Add.SubItems(1) = b
ListView1.ListItems.Add.SubItems(2) = c
End If
Next i
End Sub
但结果是这样的:
线路并不简单。 我的代码会发生什么?这是错的吗? 请帮帮我,谢谢你
答案 0 :(得分:1)
我建议你尝试这样的事情,你实际上可以使用for i循环遍历values数组,但是你得到了要点!
Private Sub Command1_Click()
Dim a As String
Dim b As String
Dim c As String
Dim i As Long
Dim sLines() As String
Dim sValues() As String
Dim oItem As ListItem
sLines() = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(sLines)
If sLines(i) > vbNullString Then ' skip for empty line
sValues() = Split(sLines(i), ".")
a = sValues(0) & vbCrLf
b = sValues(1) & vbCrLf
c = sValues(2) & vbCrLf
Set oItem = ListView1.ListItems.Add(, , sValues(0))
Call oItem.ListSubItems.Add(, , sValues(1))
Call oItem.ListSubItems.Add(, , sValues(2))
End If
Next i
End Sub