本帖最后由 bhbh202 于 2011-01-13 19:03:19 编辑

解决方案 »

  1.   


    dim I as longOpen "C:\姓名.txt" For Input As #1
        If LOF(1) > 0 Then
          
         While Not EOF(1)
          x = DoEvents
          Line Input #1, str
          Text1(i).Text =  str 
          i=i+1
         Wend
        End If
        Close #1
      

  2.   

    可以考虑用 split() 函数将一次读入的数据赋给数组,但还是得用循环将数据写入文本框,不然你不知道N等于多少.
    另外还有一个复杂化的方法,你可以用数据库的方法,将文本中的内容读入数据库中,而窗体上的文本框与数据库字段绑定,这样就用不着向文本框写值了.
      

  3.   

    Str是个函数的名字,在VB中属于保留字,尽量不要使用它作为变量的名称
    dim i as Integer
    i=0
    dim MyStr as String
    Open "C:\姓名.txt" For Input As #1
         Do While Not EOF(1) 
          Line Input #1, MyStr 
          Text1(i).Text =  MyStr 
          i=i+1
         Loop
        Close #1
      

  4.   


    实时错误340,控件组8不存在? 这里变黄了(Text1(i).Text = MyStr)         我现在(0)-----(7)个
      

  5.   

    检查一下文本文件里是不是多余8行,比如空白行
    可以这样改
    dim i as Integer
    i=0
    dim MyStr as String
    Open "C:\姓名.txt" For Input As #1
         Do While Not EOF(1) 
          Line Input #1, MyStr 
          Text1(i).Text =  MyStr 
          i=i+1
          if i>=Text1.Count Then Exit Do
         Loop
        Close #1