之前有童鞋帮我写了这个程序,可是运行之后text中显示的本文总是不正确
我的文本中有空格,有回车,可是运行完之后要么只有第一行的数,要么在第一个空格之后的就都没显示,这是怎么回事呢?
应该怎么修改呢?
Private Sub Command1_Click()
    Dim strFileName As String
    Dim intFileNo As Integer
    Dim strInput As String
On Error GoTo errSub
    With CommonDialog1
        .FileName = ""
        .DialogTitle = "打开文件"
        .Filter = "文本文件|*.txt"
        .InitDir = App.Path
    End With
    CommonDialog1.ShowOpen      '显示对话框,选择要打开的文件
    strFileName = CommonDialog1.FileName    '录入要打开的文件路径
    If strFileName <> "" Then
        '执行打开文件操作
        intFileNo = FreeFile(0)
        Open strFileName For Input As #intFileNo
        Input #intFileNo, strInput
        Close #intFileNo
        Text1.Text = strInput
    End If
    Exit Sub
errSub:End Sub

解决方案 »

  1.   

    你要把Text1设置为多行显示啊!!
    Text1.MultiLine = True
      

  2.   

    Private Sub Command1_Click()
      Dim strFileName As String
      Dim intFileNo As Integer
      Dim strInput As String
    On Error GoTo errSub
      With CommonDialog1
      .FileName = ""
      .DialogTitle = "打开文件"
      .Filter = "文本文件|*.txt"
      .InitDir = App.Path
      End With
      CommonDialog1.ShowOpen '显示对话框,选择要打开的文件
      strFileName = CommonDialog1.FileName '录入要打开的文件路径
      If strFileName <> "" Then
      '执行打开文件操作
      intFileNo = FreeFile(0)
      Open strFileName For Input As #intFileNo
      Input #intFileNo, strInput
      Text1.Text = strInput
      do while not eof(#intFileNo)
          Input #intFileNo, strInput
          Text1.Text = Text1.Text & vbcrlf & strInput
      loop
      Close #intFileNo
      
      End If
      Exit Sub
    errSub:End Sub
      

  3.   

    在textbox的属性对话框里把MultiLine属性设置为true,运行时不可更改此属性。 
      

  4.   


    Private Sub Command1_Click()
      Dim strFileName As String
      Dim intFileNo As Integer
      Dim strInput As String
    On Error GoTo errSub
      With CommonDialog1
      .FileName = ""
      .DialogTitle = "打开文件"
      .Filter = "文本文件|*.txt"
      .InitDir = App.Path
      End With
      CommonDialog1.ShowOpen '显示对话框,选择要打开的文件
      strFileName = CommonDialog1.FileName '录入要打开的文件路径
      If strFileName <> "" Then
      '执行打开文件操作
      intFileNo = FreeFile(0)
      text1.text=""
      Open strFileName For Input As #intFileNo
      do while not eof(intFileNo)
      Input #intFileNo, strInput
      Text1.Text = Text1.Text & strInput & vbcrlf 
      loop
      Close #intFileNo
       
      End If
      Exit Sub
    errSub:End Sub
      

  5.   

    建议用edttext,在vfp中:
    create mytable(myfield m)
    cfilename=getfile("txt",'打开文件')
    if not empty(cfilename)
       use mytable
       append meno myfield from (cfilename) overwrite
       thisfrom.edttext.controlsource='mytable.myfield'
       thisfrom.refresh
    endif