[Gambas-user] Program runs wild
Eilert
eilert-sprachen at ...221...
Mon Dec 20 16:56:38 CET 2004
Benoit Minisini schrieb:
> On Monday 20 December 2004 12:28, Eilert wrote:
>
>>Hi,
>>
>>this is a small Gambas app I made for monitoring who is online in the
>>system. The program calls "who" and displays the output in a list. There
>>is an LCD number showing the number of people logged in. That's all.
>>
>>There is no regular base on which the program starts going nuts. All I
>>can say is "sometimes" it starts consuming more and more processing
>>power while still keeping to run. If I stop it and restart it,
>>everything is fine again, until next time... :-)
>>
>>Here is the code:
>>
>>' Gambas class file
>>
>>PUBLIC SUB Form_Open()
>>
>> Form1.Title = "KwhoList 1.0"
>> Form1.X = 713
>> Form1.Y = 510
>> Form1.Width = 270
>> Form1.Height = 280
>>
>> whoListeLesen
>>
>>END
>>
>>PUBLIC SUB Timer1_Timer()
>>
>> whoListeLesen
>>
>>END
>>
>>PUBLIC SUB Process_Read()
>>DIM t$ AS String
>>
>> LINE INPUT #LAST, t$
>>
>> ListBox1.Add(t$)
>> LCDNumber1.Value = ListBox1.Count
>>
>>END
>>
>>
>>SUB whoListeLesen()
>>
>> ListBox1.Clear
>>
>> EXEC [ "who" ] FOR READ
>>
>>
>>
>>END
>>
>>PUBLIC SUB Form_Resize()
>>
>> ListBox1.Width = Form1.Width
>> ListBox1.Height = Form1.Height - 50
>>END
>>
>>---
>>When initiated, the program reads the list once to have a display. The
>>timer is on 10 seconds. So every 10 seconds I can see a new list.
>>
>>Any ideas where there is a reason for Gambas to start consuming 88 %
>>processing power?
>>
>>Rolf
>>
>
>
> What happens if you read data from 'who' process this way:
>
> ' Gambas class file
>
> PRIVATE $sBuffer AS String
>
> ...
>
> PUBLIC SUB Process_Read()
>
> DIM sData AS String
> DIM iPos AS Integer
>
> READ #LAST, sData, -255
>
> $sBuffer = $sBuffer & sData
>
> DO
> iPos = Instr($sBuffer, "\n")
> IF iPos = 0 then BREAK
>
> ListBox1.Add(Left$($sBuffer, iPos - 1))
> $sBuffer = Mid$($sBuffer, iPos + 1)
> LOOP
>
> LCDNumber1.Value = ListBox1.Count
>
> END
>
> ...
>
>
> Tell me the result!
>
> Regards,
>
Thank you for the tip, I'll try to run the changed code tomorrow.
By the way, when typing it in, I found that
ListBox1.Add(Left$($sBuffer, iPos -1))
resulted in an error "Comma missing". After thinking it over I tried
ListBox1.Add(Left$($sBuffer, iPos - 1))
and it was accepted. Isn't that kinda bug? Or do you intend something
special with a difference between "-1" and "- 1" ? I think, within this
context, - 1 can't mean something different than -1.
Rolf
More information about the User
mailing list