vb 怎么遍历读取Text1.Text里面的文字,用"|"分割的,显示在List上?
有个例子:(你可以使用API,但是使用文件方式可能更加简单)SubShowOnList(SourceTextAsTextBox,ToListAsListBox)DimIn...
有个例子:
(你可以使用API,但是使用文件方式可能更加简单)
Sub ShowOnList(SourceText As TextBox, ToList As ListBox)
Dim Inputstr As String
Dim TimeAt As String
TimeAt = Hex(Year(Date)) & Hex(Month(Date)) & Hex(Day(Date)) & Hex(Hour(Time)) & Hex(Minute(Time)) & Hex(Second(Time)) '生成唯一标识
Open "C:\tmp" & TimeAt & ".tmp" For Output As #1
Print #1, SourceText.Text
Close #1
Open "C:\tmp" & TimeAt & ".tmp" For Input As #1
Do Until EOF(1)
Line Input #1, Inputstr
ToList.AddItem Inputstr
Loop
Close #1
Kill "C:\tmp" & TimeAt & ".tmp"
End Sub
使用:
ShowOnList Text1, List1
这个是Text多行时候的,我想要的是不要多行的,要单行"|"分割的显示到list里面。 展开
(你可以使用API,但是使用文件方式可能更加简单)
Sub ShowOnList(SourceText As TextBox, ToList As ListBox)
Dim Inputstr As String
Dim TimeAt As String
TimeAt = Hex(Year(Date)) & Hex(Month(Date)) & Hex(Day(Date)) & Hex(Hour(Time)) & Hex(Minute(Time)) & Hex(Second(Time)) '生成唯一标识
Open "C:\tmp" & TimeAt & ".tmp" For Output As #1
Print #1, SourceText.Text
Close #1
Open "C:\tmp" & TimeAt & ".tmp" For Input As #1
Do Until EOF(1)
Line Input #1, Inputstr
ToList.AddItem Inputstr
Loop
Close #1
Kill "C:\tmp" & TimeAt & ".tmp"
End Sub
使用:
ShowOnList Text1, List1
这个是Text多行时候的,我想要的是不要多行的,要单行"|"分割的显示到list里面。 展开
1个回答
展开全部
读到内存后,用 数组=Split(内存变量,"|") 来分割就行了
然后数组写到list里就行了。
Split函数解释: 将一个字符串按照某个子字符串分割成字符数组。
Function Split(Expression As String, [Delimiter], [Limit As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare])
Member of VBA.Strings
Split a string into an array
然后数组写到list里就行了。
Split函数解释: 将一个字符串按照某个子字符串分割成字符数组。
Function Split(Expression As String, [Delimiter], [Limit As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare])
Member of VBA.Strings
Split a string into an array
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询