Link to home
Start Free TrialLog in
Avatar of BlueScreen
BlueScreen

asked on

Text Box Populating From Log/Txt file

I have several hundred log files which I need various information from.  I want to create buttons with text boxes to the right which when clicked will search the log and insert the string into the text box.

i.e. Button (Get SCSI Firmware) would search the log for the First SCSI Target go to the end of the ......... then display the firmware version in my form's text box.

I would have to be able to repeat the function for different strings to be searched for and displayed.
Avatar of fguerreiro_inix
fguerreiro_inix

This will be your button's click  


    Dim sSql As String * 5000
   
    Me.MousePointer = vbHourglass
    DoEvents
   
    iFic = FreeFile
   
    Open "c:\TESTFILE" For Random As iFic Len = Len(sSql)
   
    Get iFic, , sSql
   
    txtSql.Text = sSql
   
    Close iFic

Avatar of BlueScreen

ASKER

Sorry, it doesn't work.  Doesn't address what text is going where.  i.e. find string display in textbox

BlueSreen
Do you actually want a search function or you already have a function that will search your file
gbzhhu

Yes I need the search function and action that will display the search results in the Textbox  

TIA
BlueScreen
Adjusted points to 100
Your log files need some way of determining the begging and end of your information.

For example...
&&This is the message I am looking for*&*

If you have that, you can then do a search using the INSTR command

pos=instr(1,LookIn,LookFor,0)

Pos will be the first occurance of of the string you are looking for.

You then find the begging and the end of your messages

Here is a sample function


FindLog will open a text file and search for a userdefined substring.  You must supply the where the message starts and ends.

EXAMPLE:
MsgBox FindLog("c:\windows\tips.txt", "DOSKEY", "[", vbCrLf + vbCrLf)

this will display:


[DOSKEY]
If you want to use DOSKEY in an MS-DOS window without loading it in
Autoexec.bat or creating a startup batch script, you can go to the
Program properties and enter doskey as the startup batch file. If you
decide later that you want to have a real startup batch file, simply
move DOSKEY into this batch file.

GOOD LUCK
------------------------------------------------

Function FindLog(ByVal strLogFile As String, ByVal strSearchFor As String, ByVal strStartIdentifer As String, ByVal strEndIdentifer As String, Optional ByVal lStartAt As Long) As String

On Error Resume Next

Dim iNextFree As Integer
Dim lPos As Long
Dim lStartLook As Long
Dim lStart As Long
Dim lEnd As Long
Dim lTmp As Long
Dim strTmp As String
Dim strLookIn As String

    iNextFree = FreeFile
    strLookIn = String(FileLen(strLogFile), " ")
   
    Open strLogFile For Binary As iNextFree
        Get iNextFree, , strLookIn
    Close iNextFree
   
    If lStartAt < 0 Then Exit Function
    If lStartAt > FileLen(strLogFile) Then Exit Function
   
    If lStartAt = 0 Then lStartLook = 1 Else lStartLook = lStartAt
   
    lPos = InStr(lStartLook, strLookIn, strSearchFor, 0)
    If lPos = 0 Then Exit Function
   
    For lTmp = lPos To 1 Step -Len(strStartIdentifer)
        If Mid$(strLookIn, lTmp - Len(strStartIdentifer), Len(strStartIdentifer)) = strStartIdentifer Then
            lStart = lTmp
            Exit For
        End If
    Next
   
    If lStart = 0 Then Exit Function
   
    lEnd = InStr(lStart, strLookIn, strEndIdentifer, 0)
    If lEnd = 0 Then Exit Function
   
    FindLog = Mid$(strLookIn, lStart - 1, (lEnd - lStart) + 1)
       
End Function






Sorry this does address how I get the string from the log into the text box and how I load the log into a buffer for further string searches.  The file needs to be search over and over again, but I don't want the file displayed to the user.

i.e. Button CLick(button name SCSI Target 0) Text box returns String from log.
I don't know if I understand your last comment, but I think you are asking how to get the filename of the text file so that the user does not have to worry about it.

I would place the file location in the tag property of the button.

ie.  me.cmdSCSIButton.tag="c:\temp\scsi.txt"

then when the click event fires

do the following:
me.txtSCSI.text=Findlog(me.cmdSCSIButton.tag,me.txtSearch.text)
If there is going to be multiple entries in the file use the lstartAt property to start somewhere other then the first character!
I think what I want to do is Press a button which will automatically insert a specific string associated with the button into a textbox next to the button.  There has to be a way to do this other than at the command prompt level.
Command1.Caption = "SCSI"

Sub Command1_Click
if Command1.Tag = "" then
   Command1.tag = ffn_GetFileAsDescribedEarlier(Command1.Caption
             & ".Log" )  'look at correct file
end if
Dim start as long
Dim Finish as long
Dim Length as long
Const LookFor as string = "Login ="
Start = Instr(Command1.tag, Lookfor)
Finish = Instr(Start ,Command1.tag, ";")
Length = Finish - Start - 1   ' dont incluse the ";"
Text1.text = Mid$(Command1.tag,Start +Len(Lookfor),Length)

IT will load the VariableFile and save it locally for repeated lookups
It Will Punch in "TheAnswerMan" into your textbox

Assumes Some type of File like this..
PWD=Bubba;
Login=TheAnswerMan;
Workstation=ELBA;
ErrorCode=34;

This didn't get me there.

The file is standard output from the Compaq Survey Utility.


Adjusted points to 300
you need to explain in detail what it is you want.  I am confused if that didnt get you what you are looking for.
Okay... I think I see what you're after.  Let's assume that the log looks like:

.
SCSI Firmware=9.99.9999
DOS Version=7.00
Path=C:\
.

You want to press a button, have the routine search for "SCSI Firmware" and return "9.99.9999".  Is that right?

If you can post a snippet of the log so we can see the log syntax, we can know how to delimit the lines to return the exact text you want.  If it's like an INI file, it'll be easy, you can use GetPrivateProfileString.  Otherwise, you can write a simple loop of "Line Input #" statements to read in each individual line until you find the match you want.  Then you do an INSTR to find the position of the delimiter and voila!  You have your return value.  Then you can stick it in your textbox.

Please let me know if you want some help with it.  I'd be happy to assist.
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial