Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / qtimer

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. qtimer
#593
Posted by: 2002-10-24 03:49:12
i have a question regarding timers.

Well i can make this

dim whatever(4) as qtimer

so i can setup multiple timers using one variable.. That is nice..

But.. how do i do this:

i want the different timers acces the same code

for example..

whatever.ontimer = thred 4   '(this will not work... but i need to forward something to the sub to determine what to do since i want to use the same code for multiple timers)

sub thred (n as integer)


Tanx again
print n

end sub
Message2. Re: qtimer
#606
Posted by: guidance 2002-10-25 14:12:27
Seems not possible since ontimer event doesn't pass parameters.
Usually, I will use one timer only and call corresponding subs according to a counter variable in the ontimer event handler. The timer interval can be set with the smallest one.
This method saves a lot of the resources although looks a little bit un-clean.
Message3. qtimer agin!
#609
Posted by: 2002-10-25 15:49:37
Thanx for the answer...

And I must say my super ideas (hehe) is stopped dead in the tracks.
Well, when playing around with timers I found out the biggest limiting factors of them all..
If one of the timers is stuck waiting for something the other timers will not execute. So there is no way that I know to write multi thred QoS programs in rapidq.

As u can see when running the program below timer(0) stopps all other timers (I've put an eternal loop there as u can see)..

dim thred (4) as qtimer
dim a as integer
dim b as integer
dim c as integer
declare sub megamega
declare sub megamega2
CREATE Form AS QFORM
    Caption = "Form1"
    Width = 320
    Height = 140
    Center
    CREATE Label1 AS QLABEL
            Caption = "Label1"
        Left = 136
        Top = 24
        Transparent = 1
    END CREATE
    CREATE Label2 AS QLABEL
        Caption = "Label2"
        Left = 136
        Top = 64
        Transparent = 1
    END CREATE
END CREATE
a=0
b=0
c=0
thred(b).interval = 100
thred(b).ontimer = megamega
thred(b).enabled = 1
b++
thred(b).interval = 40
thred(b).ontimer = megamega2
thred(b).enabled = 1
Form.ShowModal
sub megamega
    thred(0).enabled = 0
megaloop1:
    a++
    label1.caption = STR$(a)
    goto megaloop1
end sub
sub megamega2
    c++
    label2.caption = STR$(c)
end sub

 
L8r dudes.

/A
Message4. Re: qtimer agin! (I was wrong)
#610
Posted by: 2002-10-25 15:58:38

I guess it's time for me to crawl back and admit that there is a way to get it all working... And I can't beleve i did'nt think about this 10 minutes ago when I posted my last message.
By adding the extremely nice function:doevents I will be able to hand over the task to the other timers pending.

so the timer should look like this and then it works.

sub megamega
    thred(0).enabled = 0
megaloop1:   
    a++
    label1.caption = STR$(a)
    doevents
    goto megaloop1
end sub

Tnx again..
Message5. Re: qtimer agin! (I was wrong)
#613
Posted by: 2002-10-25 20:27:05
But....

There is still one question that I just can't figure out.

How do I define a sub (or maby function) that I can recieve parameters from an 'on event'.

Guidance U sad that this was not possible.

"Seems not possible since ontimer event doesn't pass parameters.
Usually, I will use one timer only and call corresponding subs according to a counter variable in the ontimer event handler. The timer interval can be set with the smallest one.
This method saves a lot of the resources although looks a little bit un-clean."

But the problem is that I will run code in the timer that several 'root processes' created and each 'child process' (the actual timer code) will be in it's own state using the same code as the other child processes.. so therfore I need to know which 'master process' called the 'child process' in order to determine the correct desitions.

What about:
Declare function instead of declare sub ?   I've been playing around with that. but no working code yet..

/A
Message6. Can't understand your question :(
#614
Posted by: guidance 2002-10-25 22:37:41
?
Message7. Re: Can't understand your question :(
#615
Posted by: 2002-10-25 23:56:29
ok..
I'll make it simple..

I need several qtimers to point at the same code.
But inorder to determine what qtimer called the sub I need som kind of handle sent to the sub as well.(since all qtimers point to the same code)..

Tnx

/A
Message8. I'm afraid it's not possible.
#616
Posted by: guidance 2002-10-26 07:04:29
You have to dim/create several qtimers since ontimer event doesn't pass parameters.
Message9. Re: qtimer
#629
Posted by: 2002-11-02 20:15:22
Ph4tl4m3R - If I understand you correctly then Tags are your friend.

Try this:

DECLARE SUB Init
DECLARE SUB Which (Sender AS QTIMER)

DIM Timers(1 TO 3) AS QTIMER
DIM T(1 TO 3) AS LONG

CREATE Form AS QFORM
   CREATE Box AS QRICHEDIT
      Align = 5
      HideSelection = 0
      Font.Name = "Courier New"
   END CREATE
   OnShow = Init
   Center
   ShowModal
END CREATE

SUB Init
   FOR A = 1 TO 3
      Timers(A).Interval = A * 2000
      Timers(A).Tag = A
      Timers(A).OnTimer = Which
      T(A) = 0
   NEXT
END SUB

SUB Which (Sender)
   N = Sender.Tag
   T(N) = T(N) + N * 2
   Box.AddStrings "This is Timer " + STR$(N) + " at " + _
                                       STR$(T(N)) + " seconds"
END SUB

Message10. Re: qtimer
#630
Posted by: guidance 2002-11-02 21:43:39
Wow, thanks very much! The doc is wrong! It says OnTimer event has 0 parameter(
 
 
).
Now, I believe all event handler has at least one parameter -- Sender, no matter what the doc says! Is it true?
Message11. Re: qtimer
#631
Posted by: kohaistyle 2002-11-03 01:07:00
Hey, nice addition AEJ !

That might help me aswell ... ^^

Thx !
Message12. Re: qtimer
#633
Posted by: 2002-11-04 07:42:42
I haven't yet found a situation where Sender doesn't work - I think the docs only refer to compulsory parameters.

Nearly all components have a Tag which can be used in many useful ways from a simple 'identy code', as in my Timer demo but which the automatic TabOrder can do just as well, to things like holding &Hnnnnnn colour values, which can save an awful lot of code at times.

Message13. Re: qtimer
#640
Posted by: 2002-11-05 21:57:01

Thanx Dude!!!!

This was extremely good information!

/Phat...
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0