FIFO view using an editorGadget?

Just starting out? Need help? Post your questions and find answers here.
JElliott
User
User
Posts: 16
Joined: Mon Sep 03, 2007 3:44 pm
Location: Connecticut, USA

FIFO view using an editorGadget?

Post 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.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

I didn't think of just removing one line at a time from the editor. :oops:
JElliott
User
User
Posts: 16
Joined: Mon Sep 03, 2007 3:44 pm
Location: Connecticut, USA

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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. :lol:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Sparkie wrote: I still miss the obvious every now and then. :lol:
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.
Post Reply