dim mystring as string
mystring = text1.text

解决方案 »

  1.   

    简单:dim lenfile as integer
    dim filenum as integer
    filenum=freefile()
    open "file.dat" for input as filenum
    lenfile=lof(#filenum)
    strfile=input(lenfile,#filenum)'将所有数据放入变量strfile中
    close filenum
      

  2.   

    'Use FSO
     'Add the reference of Microsoft Scripting Runtime'Reading Files with File System Objects
    'To read data from a text file, use the Read, ReadLine, or ReadAll methods of the TextStream object:'Task                                                                  Method
    'Read a specified number of characters from a file                     Read
    'Read an entire line (up to, but not including, the newline character) ReadLine
    'Read the entire contents of a text file                               ReadAll
    Private Sub Form_Load()
       Const ForReading = 1, ForWriting = 2
       Dim fso, f
       Dim SkipLineInFile As String
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
       f.Write "Hello world!" & vbCrLf & "VB Script is fun!"
       Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
       SkipLineInFile = f.readall
       Debug.Print SkipLineInFileEnd Sub'显示:
    'Hello world!
    'VB Script Is fun!
      

  3.   

    dim a()as byte
    open "C:\msdos.sys"for binary as #1
    redim aa(lof(1)-1)
    get#1,,aa
    close#1
      

  4.   

    把文本文件内容读取TextBox:
    Dim TempFile As Long
    Dim LoadBytes() As ByteTempFile=FreeFile
    Open 文件名 For Binary As #TempFile
    Redim LoadBytes(1 To Lof(TempFile)) As Byte
    Get #TempFile,,LoadBytes
    Close TempFileText1.Text=StrConv(LoadBytes,vbUniCode)