1.如何实现删除文本中的一行
2.如何实现保存被修改过的文本文件
3.如何判断一个被打开的文本文件的大小
4.如何判断一个运行此程序的计算机的操作系统
5.如何判断一个MDI窗体内有没有子窗体

解决方案 »

  1.   

    判断操作系统Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End Type
    Private Sub Form_Load()
        Dim OSInfo As OSVERSIONINFO, PId As String    'Set the graphical mode to persistent
        Me.AutoRedraw = True
        'Set the structure size
        OSInfo.dwOSVersionInfoSize = Len(OSInfo)
        'Get the Windows version
        Ret& = GetVersionEx(OSInfo)
        'Chack for errors
        If Ret& = 0 Then MsgBox "Error Getting Version Information": Exit Sub
        'Print the information to the form
        Select Case OSInfo.dwPlatformId
            Case 0
                PId = "Windows 32s "
            Case 1
                PId = "Windows 95/98"
            Case 2
                PId = "Windows NT "
        End Select
        Print "OS: " + PId
        Print "Win version:" + str$(OSInfo.dwMajorVersion) + "." + LTrim(str(OSInfo.dwMinorVersion))
        Print "Build: " + str(OSInfo.dwBuildNumber)
    End Sub
      

  2.   

    文本的读取和修改把文本文件内容读取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)把TextBox内容写入文本文件:
    Dim TempFile As Long
    Dim SaveBytes() As ByteSaveBytes=StrConv(Text1.Text,vbFromUniCode)TempFile=FreeFile
    Open 文件名 For Binary As #TempFile
    Put #TempFile,,SaveBytes
    Close TempFile
      

  3.   

    文件大小'GetFileSizeExConst GENERIC_READ = &H80000000Const FILE_SHARE_READ = &H1Const OPEN_EXISTING = 3Const FILE_TYPE_CHAR = &H2Const FILE_TYPE_DISK = &H1Const FILE_TYPE_PIPE = &H3Const FILE_TYPE_UNKNOWN = &H0Private Declare Function GetFileType Lib "kernel32" (ByVal hFile As Long) As LongPrivate Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As LongPrivate Declare Function GetFileSizeEx Lib "kernel32" (ByVal hFile As Long, lpFileSize As Currency) As BooleanPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Sub Form_Paint()    'KPD-Team 2000    'URL: http://www.allapi.net/    'E-Mail: [email protected]    Dim hFile As Long, nSize As Currency, sSave As String    'open the file    hFile = CreateFile("c:\autoexec.bat", GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, ByVal 0&, ByVal 0&)    'get the filesize    GetFileSizeEx hFile, nSize    'retrieve the file type    Select Case GetFileType(hFile)        Case FILE_TYPE_UNKNOWN            sSave = "The type of the specified file is unknown"        Case FILE_TYPE_DISK            sSave = "The specified file is a disk file"        Case FILE_TYPE_CHAR            sSave = "The specified file is a character file, typically an LPT device or a console"        Case FILE_TYPE_PIPE            sSave = "The specified file is either a named or anonymous pipe"    End Select    'close the file    CloseHandle hFile    MsgBox "File Type: " + sSave + vbCrLf + "Size:" + Str$(nSize * 10000) + " bytes"End Sub
      

  4.   

    判断MDI子窗体   
              Dim N As Form
                 Dim I As Integer
                 Set N = Me.ActiveForm
                  For Each Form In Forms
                      I = I + 1
                  Next
                  If I > 1 Then
                      MSGBOX"有子窗体"
                  ELSE
                      MSGBOX"没有子窗体"
                  End If
      

  5.   

    删除文件一条(行)记录Private Type info
        Name As String * 20
        Value As String * 40
    End Type
    Private Sub cmdDel_Click()
    On Error Resume Next
    Dim A As info
    Dim sum As Integer, i As Integer, Count As Integer
    Count = 0
    Open "tempfile.dat" For Random As #2 Len = Len(A)
    Open "myfile.dat" For Random As #1 Len = Len(A)
    sum = LOF(1) \ Len(A)
    For i = 1 To sum
        If i <> 8 Then 'No. you want kill
            Count = Count + 1
            Get #1, i, A
            Put #2, Count, A
        Else
            msgbox "killed!"
        End If
    Next i
    Close #1, #2Kill "myfile.dat"
    Name "tempfile.dat" As "myfile.dat"
    End Sub