GoGreen PC TuneUp™
Learn More

Insta-Install™
this is how we code sign our software and ssl encrypt our websites from our affiliate partner SSL.com

myBlog

myBlog Home

Back to Blog List View Table View MTNCOMP


VB Classic, Instr, File I/O for any language

by Mountain Computers Inc., Publication Date: Thursday, February 21, 2019
View Count: 1060, Keywords: GGPCTU, File I/O, Instr, Hashtags: #GGPCTU #FileI/O #Instr



 
here is snippit of code for processing a log file, from an old and new app that I support
 
you can do more with it if you like...
 
Private Sub AnalyzeLogFile(f)
Debug.Print "AnalyzeLogFile()"
Screen.MousePointer = vbHourglass
'analyze the log files either in the app or current exe directory
'f is a function variable
'myf is the file to scan
'n count of instr string found

Dim myf, n, memval, memmax, memmin, memtot
myf = ""
n = 0
memval = ""
memmax = 0
memmin = 100
memtot = 0

If f <> "" Then
    myf = f
Else
    myf = App.Path & "\ggpctu-log.txt"
End If

If Dir(myf) <> "" Then
    'log file exists
    Dim sFileText As String
    Dim sLineText As String
    Dim iFileNo As Integer
      iFileNo = FreeFile
          'open the file for reading
      Open myf For Input As #iFileNo
    'change this filename to an existing file!  (or run the example below first)
          'read the file until we reach the end
      Do While Not EOF(iFileNo)
        memval = ""
        sLineText = ""
        Input #iFileNo, sFileText
          'show the text (you will probably want to replace this line as appropriate to your program!)
       'Debug.Print sFileText
        If InStr(sFileText, "Memory Load") > 0 Then
            'found memory load string, process it
            'Debug.Print "Found Memory Load entry... looking for % in " & sFileText
            sLineText = InStr(sFileText, "%")
            memval = Val(Mid(sFileText, sLineText - 3, 3))
            'Debug.Print "val = " & memval
            If memval > memmax Then
                memmax = memval
            End If
            If memval < memmin Then
                memmin = memval
            End If
            memtot = memtot + memval
            n = n + 1
        End If
      Loop
          'close the file (if you dont do this, you wont be able to open it again!)
      Close #iFileNo
Else
    'log file does not exist
End If
Debug.Print "Memory Count = " & n & ", Max = " & memmax & ", Min = " & memmin & ", Avg = " & memtot / n
'hstry.AddItem "# of Memory Entries: " & n & ", Max: " & memmax & ", Min: " & memmin & ", Avg: " & Round((memtot / n), 2)
ol.AddItem "# Memory Load Entries: " & n & ", Max: " & memmax & ", Min: " & memmin & ", Avg: " & Round((memtot / n), 2)
Screen.MousePointer = vbNormal
End Sub
 
more to come...
 

if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.

© 2021 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.