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)
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
myf = App.Path & "\ggpctu-log.txt"
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!)
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
If memval < memmin Then
memmin = memval
memtot = memtot + memval
n = n + 1
'close the file (if you dont do this, you wont be able to open it again!)
'log file does not exist
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
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.