Solved

Text Box Populating From Log/Txt file

Posted on 1998-09-28
15
152 Views
Last Modified: 2010-04-30
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.
0
Comment
Question by:BlueScreen
  • 7
  • 2
  • 2
  • +4
15 Comments
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1437023
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
 
LVL 1

Author Comment

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

BlueSreen
0
 
LVL 12

Expert Comment

by:gbzhhu
ID: 1437025
Do you actually want a search function or you already have a function that will search your file
0
 
LVL 1

Author Comment

by:BlueScreen
ID: 1437026
gbzhhu

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

TIA
BlueScreen
0
 
LVL 1

Author Comment

by:BlueScreen
ID: 1437027
Adjusted points to 100
0
 

Expert Comment

by:jfayling
ID: 1437028
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
 
LVL 1

Author Comment

by:BlueScreen
ID: 1437029
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:jfayling
ID: 1437030
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
 
LVL 1

Author Comment

by:BlueScreen
ID: 1437031
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
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1437032
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
 
LVL 1

Author Comment

by:BlueScreen
ID: 1437033
This didn't get me there.

The file is standard output from the Compaq Survey Utility.


0
 
LVL 1

Author Comment

by:BlueScreen
ID: 1437034
Adjusted points to 300
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1437035
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
 
LVL 2

Expert Comment

by:kswinney
ID: 1437036
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
 
LVL 13

Accepted Solution

by:
Mirkwood earned 300 total points
ID: 1437037
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now