CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 1999
    Location
    Washington
    Posts
    1

    VB code to open text files for editing

    Does anyone have any code that will open a text file for editing. Specifically, I wish to open 4 text files and erase the first line of text and then save each of the files under a new file name.
    Any help would be appreciated.
    thank you.


  2. #2
    Join Date
    Oct 1999
    Location
    Austria
    Posts
    10

    Re: VB code to open text files for editing

    Hi Larry
    try to solve your problem with the notepad:

    First you need to declare some functions (maybe, you'll need not all of them, just try it) and constants

    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Private Declare Function GetFileAttributes Lib "kernel32.dll" _
    Alias "GetFileAttributesA" _
    (ByVal lpFileName As String) As Long


    Private Const STILL_ACTIVE = &H103
    Private Const PROCESS_QUERY_INFORMATION = &H400

    I had to modify a ini-file, so I wrote the function ModifyIni:
    call the function:
    ModifyIni "NOTEPAD PKSWFRV.INI", vbNormalFocus


    Public Function ModifyIni(ByVal JobToDo As String, Optional ExecMode) As Long

    Dim ProcessID As Long
    Dim hProcess As Long
    Dim nRet As Long
    Const fdwAccess = PROCESS_QUERY_INFORMATION

    On Error Resume Next
    ProcessID = Shell(JobToDo, CLng(ExecMode))
    If Err Then
    ModifyIni vbObjectError + Err.Number
    Exit Function
    End If
    On Error GoTo 0

    hProcess = OpenProcess(fdwAccess, False, ProcessID)
    Do
    GetExitCodeProcess hProcess, nRet
    DoEvents
    Sleep 100
    Loop While nRet = STILL_ACTIVE

    Call CloseHandle(hProcess)

    ModifyIni = nRet
    End Function


    regards,Peter


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured