菜问题!按行读取文本文件“chen.txt”,并按行将数据附给变量string1,.....string10 给100!!

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim strTmp  As String, strArray() As String
        
        Open "C:\chen.txt" For Input As #1
        strTmp = StrConv(InputB(LOF(1), #1), vbUnicode)
        Close #1
        strArray = Split(strTmp, vbCrLf) '将文件内容按行分别存到数组中,一个数组元素代表一行,不用单个变量了~~
    End Sub
      

  2.   

    首先将文本框的mulline属性设置为多行文本,
    dim  strtext as string
    dim str() as string
    dim i as integer
    str=split(strtext,vbcrlf)  'splict函数将每一行文本赋值给数组。以上代码包你好用,如有不明白之处请回复〉
      

  3.   


    赋值给变量
    open "c:\chen.txt" for input as #1
        line input #1,string1
        line input #1,string2
        line input #1,string3
        line input #1,string4
        line input #1,string5
        line input #1,string6
        line input #1,string7
        line input #1,string8
        line input #1,string9
        line input #1,string10
    close #1赋值到数组
    dim strt(0 to 9) as string
    open "c:\chen.txt" for input as #1
        for i = 0 to 9
            line input #1,string(i)
        next
    close #1
    如果chen.txt文件不在或者chen.txt行数没10行则会出错
    最好加上判断
      

  4.   

    open "c:\chen.txt" for input as #1
        line input #1,string1
        line input #1,string2
        line input #1,string3
        line input #1,string4
        line input #1,string5
        line input #1,string6
        line input #1,string7
        line input #1,string8
        line input #1,string9
        line input #1,string10
    close #1
      

  5.   

    想复杂了!典型的计算机等级考试2级VB题,通常Chen.txt中的内容是由空格间隔的,然后要求将其内容读到个数组中,并显示出来(通常是分组),呵呵。
    答案通常是:
    dim arr(10,10)
    open "c:\chen.txt" for input as #1
    for i=1 to 10
       for j=1 to 10      '通常考点在这
          input #1,arr(i,j)   next j,i
    close #1
    呵呵!
      

  6.   

    前10行就这样:
    open "c:\chen.txt" for input as #1
        line input #1,string1
        line input #1,string2
        line input #1,string3
        line input #1,string4
        line input #1,string5
        line input #1,string6
        line input #1,string7
        line input #1,string8
        line input #1,string9
        line input #1,string10
    close #1也可以这样:Private Sub Command1_Click()
        Dim s As String
        Open "C:\chen.txt" For Binary As 1
        s = String(FileLen("c:\chen.txt"), " ")
        Get #1, , s
        Close #1
      temp = Split(s, vbCrLf)
      string1 = temp(0)
      string2 = temp(1)
      '.....
    End Sub