How to constantly refresh 20 lines in dialog's memo chrono.?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
doa
Newbie
Posts: 7
Joined: Thu Sep 20, 2012 4:25 pm

How to constantly refresh 20 lines in dialog's memo chrono.?

Post by doa » Fri Oct 05, 2012 3:37 pm

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

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Oct 05, 2012 4:33 pm

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


doa
Newbie
Posts: 7
Joined: Thu Sep 20, 2012 4:25 pm

Post by doa » Fri Oct 05, 2012 7:20 pm

Yes, JRL, as much as I can see, you are my saver, that is it, but I am on v11 and

AddDialogHandler> and SetDialogProperty> are not supported :cry:

So, how can I "replace" these functions ?

Thank you very much in advance

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Oct 05, 2012 7:33 pm

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

doa
Newbie
Posts: 7
Joined: Thu Sep 20, 2012 4:25 pm

Post by doa » Fri Oct 05, 2012 8:34 pm

Thanksss man and all the best !

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts