Huh, I am new and all these dialogs....,it seems I can't make it.
I should constantly read some log file and show it's last 20 lines in ms dialog chronologically and so to say the last one from log should be the first one in dialog, the 19th should be the second one and so on till all last 20 lines.
How to organize variables and loops, some example would be nice ?
I hope it is not so difficult
Thank you very much
How to constantly refresh 20 lines in dialog's memo chrono.?
Moderators: Dorian (MJT support), JRL
Here's a starting point or maybe all you need. Be sure to set the "LogFileName" variable to your log file location and name.
Code: Select all
OnEvent>key_down,VK27,0,Quit
Let>LogFileName=YOURFILE
VBSTART
Function LineCount(sFilespec)
Const ForAppending = 8
with CreateObject("Scripting.FileSystemObject")
LineCount = .OpenTextFile(sFilespec, ForAppending).Line
end with
end Function
VBEND
Dialog>Dialog1
object Dialog1: TForm
AutoSize = True
Caption = 'Last 20 Log File Lines, Last Line First'
Position = poScreenCenter
object MSListBox1: tMSListBox
Left = 0
Top = 0
Width = 600
Height = 500
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,,OnClose,Quit
Show>Dialog1
Label>Loop
GoSub>Process
Wait>5
Goto>Loop
SRT>Process
Let>DisplayList=
VBEval>LineCount("%LogFileName%"),Line_Count
Let>kk=Line_count
Repeat>kk
Sub>kk,1
ReadLn>LogFileName,kk,Line
Let>DisplayList=%DisplayList%%Line%%crlf%
Until>kk={%Line_Count%-20}
SetDialogProperty>Dialog1,MSListBox1,Text,DisplayList
END>Process
SRT>Quit
GetActiveWindow>AWinT,AWinX,AWinY
If>AWinT=Last 20 Log File Lines, Last Line First
Exit>0
EndIf
END>Quit
Same thing, Pre-V12 code
Code: Select all
OnEvent>key_down,VK27,0,Quit
Let>LogFileName=%temp_dir%LogFile.txt
VBSTART
Function LineCount(sFilespec)
Const ForAppending = 8
with CreateObject("Scripting.FileSystemObject")
LineCount = .OpenTextFile(sFilespec, ForAppending).Line
end with
end Function
VBEND
Dialog>Dialog1
Caption=Last 20 Log File Lines, Last Line First
Width=608
Height=530
Top=CENTER
Left=CENTER
ListBox=msListBox1,0,0,600,500,
EndDialog>Dialog1
Show>Dialog1
Label>Loop
GetDialogAction>Dialog1,res1
If>res1=2
Gosub>Quit
EndIf
GoSub>Process
Wait>5
Goto>Loop
SRT>Process
Let>DisplayList=
VBEval>LineCount("%LogFileName%"),Line_Count
Let>kk=Line_count
Repeat>kk
Sub>kk,1
ReadLn>LogFileName,kk,Line
Let>DisplayList=%DisplayList%%Line%%crlf%
Until>kk={%Line_Count%-20}
Let>Dialog1.MSListBox1.Items.Text=DisplayList
ResetDialogAction>Dialog1
END>Process
SRT>Quit
GetActiveWindow>AWinT,AWinX,AWinY
If>AWinT=Last 20 Log File Lines, Last Line First
Exit>0
EndIf
END>Quit