Page 1 of 1
FIFO view using an editorGadget?
Posted: Mon Sep 10, 2007 2:59 pm
by JElliott
I was wondering if it is possible to create a FIFO view using the editorGadget? What I want to do is display the last "n" entries made into the gadget in a FIFO fashion. This is for a serial port monitor/logger. Each line sent gets displayed in an editorGadget then logged to a file - line by line. Visually in the editor gadget I really only want to be able to see the last 100 lines or so. Also since this monitor will run for days I don't want the editorGadget to get overloaded and fail. Right now I'm counting the lines in the gadget and just deleting all of them when they reach a certain amount.
It's not obvious to me if I can do this with the editorGadget.
Just a word of praise for PB - I've been using it for only a week and have accomplished more than I did with VB in 6 months. I'm very impressed with the available functionality and easy of use.
Thanks,
Jeff E.
Posted: Mon Sep 10, 2007 4:29 pm
by Derek
First thing that springs to mind is to use an array and keep the strings in that using a fifo approach, actually using a pointer to the next entry and rotating it, so with an array of 100 strings you would put the next strings into 1,2,3 etc upto 98,99,100 and then back to 0.
From this array you could just keep displaying the strings in an editor gadget but this is where the problem lies as you would have to clear and refill the gadget with all 100 lines each time you get a new string.
Perhaps using a different kind of gadget would be preferable.
Posted: Mon Sep 10, 2007 5:42 pm
by Sparkie
Welcome to PB JElliott
Maybe I'm missing the point, but how about something like this...
Code: Select all
If OpenWindow(0, 0, 0, 400, 400, "FIFO EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
EditorGadget(0, 5, 5, 390, 250)
ButtonGadget(1, 5, 300, 100, 25, "Add line")
For a = 1 To 100
AddGadgetItem(0, -1, "Line "+Str(a))
Next
totalCount = 100
SendMessage_(GadgetID(0), #EM_SCROLLCARET, 0, 0)
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget And EventGadget() = 1
totalCount + 1
AddGadgetItem(0, count-1, "Line " + Str(totalCount))
SendMessage_(GadgetID(0), #EM_SCROLLCARET, 0, 0)
SendMessage_(GadgetID(0), #EM_SCROLL, #SB_PAGEDOWN, 0)
count = CountGadgetItems(0)
If count > 100
RemoveGadgetItem(0, 0)
EndIf
EndIf
Until event = #PB_Event_CloseWindow
EndIf
Posted: Mon Sep 10, 2007 8:02 pm
by Derek
I didn't think of just removing one line at a time from the editor.

Posted: Mon Sep 10, 2007 8:58 pm
by JElliott
Sparkie - you aren't missing anything, this is precisely what I wanted to do - I have inserted it in my code and it works great!
My ignorance of the breadth of the available commands is my biggest hindrance right now. I want to thank both you and Derek for your quick responses.
Jeff E.
Posted: Mon Sep 10, 2007 10:07 pm
by Sparkie
You are very welcome.
JElliot wrote:My ignorance of the breadth of the available commands is my biggest hindrance right now
We have ALL been there at one time or another. Hell, I
still miss the obvious every now and then.

Posted: Mon Sep 10, 2007 10:28 pm
by Derek
Sparkie wrote:
I
still miss the obvious every now and then.

I
always seem to miss the obvious and try to find a far more awkward way, thank god for Sparkie, Netmaestro, Srod and all the others.