Results 1 to 8 of 8
  1. #1
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Parsing Data From Log Files

    For Button1 you might set up 2 arrays, read all the files into one of them, and then present the array for selection, and if a filename is selected you can set a flag inr the equivalent element of the 2 nd array. Then your code could run through the array of filenames and where the flag is set load the file and get the required data.

    For the other 2 buttons, well that depends. What is the exavt structure of the exact structure of the Log files, how many lines does each contain and are they fixed width ?

    Do you want just one text file containing your parsed data at the end of the operation ?

    Andrew C

  2. #2
    MitzEclipse
    Guest

    Parsing Data From Log Files

    Parsing Data From Log Files

    I'm currently working on this program that wil parse data from about 200 log files. These log files contain the phrase "Number of Current connections =>X" where X=some value (ex: 23). Since there are two machines these log files monitor, the phrase "Number of..." appears twice.

    I would like to parse the data so that I can extract "X" from the two places within the log file, and dump the data into a text file.

    I have my VB program setup so that there are 3 command buttons: 1) select the files to parse 2) parse the files and dump into a text file 3) view the text file.

    Button 1) - I used the common dialog to bring up the "file open" menu that comes built in with VB. Problem is I can only select ONE file at a time... how do I select the 200+ files I need to parse?

    Button 2) - I don't have a clue on how this button will work because even though I did select the files (from button1) how will the program know to interact with those selected files? I also want the program to bring up a box that says "what would you like to name this file for output" and when you type in something like "stats.txt" it will write it a directory that the user specifies

    Button 3) - This shouldn't be that hard, but I've tried multiple commands and I don't know what the command is to just simply open the text file in notepad. I've tried "open" "show" "load" and all those don't pertain to what I want to do. I've also experimented with creating a new form called "frmResults" and within that lies a text box...problem is I can't figure out how to populate the text box from the file created in button 2.

    Any tips would be greatly appreciated! Thanks in advance!!!

  3. #3
    MitzEclipse
    Guest

    Re: Parsing Data From Log Files

    bump

  4. #4
    MitzEclipse
    Guest

    Re: Parsing Data From Log Files

    Yes, thankfully the log files are fixed width. They are about 1 and a half pages printed out....not sure how many exact lines that is.

    Yes, just one data file at the end of the operation with the parsed info in it. Right now button 3 is programmed to bring up another form called frmResults. There is a txtResults box in the middle that is already programmed to display the contents of c:tempstats.txt. Another question -- how do you program the "SELECT ALL" button and the "COPY TO CLIPBOARD" button?

    Thanks!

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Parsing Data From Log Files

    >I used the common dialog to bring up the "file open" menu that comes built in with VB.
    >Problem is I can only select ONE file at a time... how do I select the 200+ files I need to parse?

    If you want all the .txt files in a particular folder (user selected path), you could do this:

    Sub ProcessFiles()
    '... get user path selection...
    Dim strFileToOpen As String
    strFileToOpen = Dir(path & "*.txt")
    Do
    'open file
    'how you do this depends on whether you want to use crusty but efficient old
    'BASIC techniques or treat it as a document

    'next line for debug only
    MsgBox strFileToOpen

    'process file
    '...

    'get name of next file
    strFileToOpen = Dir
    If strFileToOpen = vbNullString Then Exit Do
    Loop
    End Sub

  6. #6
    MitzEclipse
    Guest

    Re: Parsing Data From Log Files

    thanks for the help --

    I only need to just change the file type to *.log rather then having the "file open" menu be blank. this way the user automatically searches just for log files.

    thanks

  7. #7
    MitzEclipse
    Guest

    Re: Parsing Data From Log Files

    I've been able to successfuly program Button 1 to open *.msg and *.* files. I've also set it so that once it opens a certain file it will display the files within a text box. My problem now is to parse my file and extract the data that I need. Here is what I have so far -- any suggestions would be greatly appreciated!

    Private Sub cmdExit_Click()
    End
    End Sub

    Private Sub cmdStep1_Click()
    'Set default file types
    CommonDialog1.Filter = "Tuxedo Log Files (*.msg)|*.msg|All Files (*.*)|*.*"
    CommonDialog1.FilterIndex = 0
    'Open File Dialog
    CommonDialog1.Flags = cdlOFNAllowMultiselect
    CommonDialog1.ShowOpen
    FileName = CommonDialog1.FileName
    End Sub

    Private Sub cmdStep2_Click()
    'Load file system for dumping data
    Set fs_dumping = CreateObject("Scripting.FileSystemObject")
    Set output_file = fs_dumping.CreateTextFile("c:temptuxstats.txt", True)
    output_file.WriteLine ("This is a test.")
    output_file.Close

    'Load file system for reading data
    Set fs_reading = CreateObject("Scripting.FileSystemObject")
    Set input_file = fs_reading.OpenTextFile(CommonDialog1.FileName)

    'Scanning through selected files
    Dim fso, ScannedFiles
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ScannedFiles = fso.OpenTextFile("c:temptuxstats.txt", 2, True)

    Dim SearchChar, Character
    'Search for "> "
    SearchChar = "> "

    'Loop that reads each line by line
    Dim oneline As String
    Do
    oneline = input_file.readline() 'textstream
    Found_Object = InStr(1, oneline, SearchChar, 36)
    If Found_Object > 0 Then Exit Do
    Loop Until oneline = "*"
    MsgBox ("found")

    'Dim SearchString, SearchChar
    'Create Search String
    SearchString = "connections=> "
    'Return Search String
    SearchChar = Mid(SearchString, 13, 1)
    ScannedFiles.Close

    'Closing FS
    input_file.Close
    MsgBox ("Written!")

    Dim filenum As Integer
    filenum = FreeFile
    Open CommonDialog1.FileName For Input As filenum

    End Sub

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Parsing Data From Log Files

    I never work with these objects, but maybe I can help anyway.

    You seem to have the code to find the ">" in the file, but then you are not working with the variable that contains it ("oneline"). Here, in rough pseudocode, is what I suggest; you already have the first 3 lines:

    1. Read line from input file into string-variable oneline
    2. If oneline contains > then stop looping, continue at step 4
    3. Start over at 1
    4. Extract the string that follows the >

    NumWeWant = Mid(oneline, Found_Object + 1, Len(oneline) - Found_Object)

    5. Write NumWeWant to the output file (or store it for writing later)
    6. Repeat, to get SecondNumWeWant from the input file
    7. Close the input file
    8. Start on the next input file

    I like using Stop statements liberally in my VBA code to inspect variables. Might help in this case.

    Is this all the steps? Which steps work and which don't?

Posting Permissions

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