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.
LVL 1
BlueScreenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fguerreiro_inixCommented:
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

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

BlueSreen
0
gbzhhuCommented:
Do you actually want a search function or you already have a function that will search your file
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

BlueScreenAuthor Commented:
gbzhhu

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

TIA
BlueScreen
0
BlueScreenAuthor Commented:
Adjusted points to 100
0
jfaylingCommented:
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






0
BlueScreenAuthor Commented:
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.
0
jfaylingCommented:
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!
0
BlueScreenAuthor Commented:
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.
0
TheAnswerManCommented:
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;

0
BlueScreenAuthor Commented:
This didn't get me there.

The file is standard output from the Compaq Survey Utility.


0
BlueScreenAuthor Commented:
Adjusted points to 300
0
TheAnswerManCommented:
you need to explain in detail what it is you want.  I am confused if that didnt get you what you are looking for.
0
kswinneyCommented:
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.
0
MirkwoodCommented:
Use
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Example:
dim szValue as string * 255
GetPrivateProfileString "", "Path", "<Not found>", szValue, 255, "myfile.ini"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.