使用VB如何把文本文件(数字和字母相间排列)分别读到两个数组(数字和字母)
哎,我是新手,能力有限,只能做到这样了: 一个是3,5,6,6,7, 一个是e,f,a,d,e,s, 就是不会把连续的弄到一起。 新建三个文本框,两个按钮。 Private Sub Command1_Click() '读取文本文件 Dim Lstr As String Open "D:\\data。 txt" For Input As #1 Do While Not EOF(1) Line Input #1, Lstr Text1。Text = Text1。Text & Lstr & vbCrLf Loop Close #1 End Sub Private Sub Command2_Cl...全部
哎,我是新手,能力有限,只能做到这样了: 一个是3,5,6,6,7, 一个是e,f,a,d,e,s, 就是不会把连续的弄到一起。 新建三个文本框,两个按钮。 Private Sub Command1_Click() '读取文本文件 Dim Lstr As String Open "D:\\data。
txt" For Input As #1 Do While Not EOF(1) Line Input #1, Lstr Text1。Text = Text1。Text & Lstr & vbCrLf Loop Close #1 End Sub Private Sub Command2_Click() '按要求写到数组,并显示。
Text2。Text = "": Text3。Text = "" Dim a(1 To 99), b(1 To 99) as integer dim x, i, i1, j, j1, n As Integer Dim st As String st = Text1。
Text i1 = 1: j1 = 1 For i = 1 To Len(st) n = Asc(Mid(st, i, 1)) '将每个字符都转化成AscII码。 If n >= 48 And n <= 57 Then '判断是否为数字。
a(i1) = Mid(st, i, 1) '记录到数组 i1 = i1 + 1 Else b(j1) = Mid(st, i, 1) j1 = j1 + 1 End If Next For x = 1 To Len(st) '在文本框 中显示。
Text2。Text = Text2。Text & a(x) & "," Text3。Text = Text3。Text & b(x) & "," Next End Sub另外楼上那位的,没读文本文件功能,帮他改下。
。。就可以直接运行了。。。Private Sub Command1_Click() '读取文本文件 Dim Lstr As String Open "D:\\data。txt" For Input As #1 Do While Not EOF(1) Line Input #1, Lstr Text1。
Text = Text1。Text & Lstr & vbCrLf Loop Close #1 End Sub Private Sub Command3_Click()Form1。ClsDim a(20) As StringDim b(20) As StringDim m1 As StringDim m2 As Stringstr1 = Text1。
Texta1 = 0:b1 = -1a(a1) = Mid(str1, 1, 1)For i = 1 To 20m1 = Mid(str1, i, 1)m2 = Mid(str1, i + 1, 1)s1 = isstr(m1)s2 = isstr(m2)If s1 = s2 And s1 = "1" Thena(a1) = a(a1) + m2ElseIf s1 = s2 And s1 = "2" Thenb(b1) = b(b1) + m2ElseIf s1 <> s2 And s2 = "1" Thena1 = a1 + 1a(a1) = m2ElseIf s1 <> s2 And s2 = "2" Thenb1 = b1 + 1b(b1) = m2End IfNextFor i = 0 To 15Print "a(" & i & ")=" & a(i) & ",b(" & i; ")=" & b(i)NextEnd SubFunction isstr(aaa As String) As StringIf "a" <= LCase(aaa) And "z" >= LCase(aaa) Thenisstr = "2"Elseisstr = "1"End IfEnd Function。
收起