May 08, 2024, 09:31:17 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


How Implemented Timers into EBASIC

Started by Techno, September 15, 2007, 01:55:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

Dear programmers

I have an VB code and I will this rewritten into EBASIC but how can I do that?



1) How Can I this written into EBASIC = ?

Private Sub Timer1_Timer()
 
End Sub

2) Whish command have I needed for set the timer en stop the Timer

Timer1.Interval = 20

- WinAPI commands ?
- EBASIC commands ?



I'm written an application and thats the problems for converted into EBASIC.

Dogge

September 15, 2007, 03:19:10 AM #1 Last Edit: September 15, 2007, 03:23:56 AM by Dogge
Hi,
use StartTimer and StopTimer to manage your timers. The generated timer event can either be handled in the normal message loop for a window or dialog or the event could call a subroutine.

It's well documented in the manual.


Barney

Examples of timer usage can also be found in the following source files, available in the c:\Program Files\EBDev\projects folder:

clipping_example.eba
colorpicker.eba
controldemo.eba
draw.eba
keno.eba
lines.eba
memmonitor.eba
polygons.eba
sparkles.eba
winmcidemo.eba

And as Dogge said, those two instructions (STARTTIMER and STOPTIMER) are well documented in the help file.

Barney

Techno

Hello

I don't understand where do you set the timer in de events functions or in your main program?

Can you give an example:

1. Where I declare and set the Timer
2. And where the events occurs it's with @idTimer

Dogge

You can have a StartTimer almost anywhere, it is not declared as you do it in VB, just issue the command.

The event is a normal windows event that you receive in the normal eventhandler for a window or dialog
from the keno.eba file


SUB playhandler
SELECT @CLASS
        ...
CASE @IDTIMER
if picked < 20
GOSUB pickball
picked = picked + 1
GOSUB drawballs
else
GOSUB endplay
playing = 0
endif
ENDSELECT
RETURN
ENDSUB
....
SUB startplay
IF selectcount > 0
                ...
STARTTIMER playwin,100
ENDIF
RETURN
ENDSUB
...
SUB endplay
STOPTIMER playwin
        ...
RETURN
ENDSUB



You can have multiple timers by adding an ID to the StartTimer and StopTimer commands and testing for the ID in the @CODE variable in the message loop

Techno

Hi

What do you main?

"You can have multiple timers by adding an ID to the StartTimer and StopTimer commands and testing for the ID in the @CODE variable in the message loop"

Can you give me an example

Ionic Wind Support Team

Read the users guide Stephane.  Alphabetical command reference -> STARTTIMER

Read the users replies above listing the working examples, study them in detail.

Follow the directions given. 

Ionic Wind Support Team

GWS

Here's a little example : :)


window win
int style, run, recton, circleon

style = @MINBOX|@MAXBOX|@SIZE
OPENWINDOW win,0,0,600,400,style,0,"Timer Example",&winh
setwindowcolor win,rgb(0,0,80)

' start a 1 second timer
starttimer win,1000,1
' start a 2 second timer
starttimer win,2000,2

run = 1

WAITUNTIL run = 0
' before closing stop any timers used ..
stoptimer win,1
stoptimer win,1
closewindow win
END

SUB winh
SELECT @CLASS
case @IDCLOSEWINDOW
run = 0
case @idtimer
select @code
case 1
' deal with timer 1
if recton = 0
RECT win,0,0,100,100,RGB(255,0,0),RGB(0,0,255)
recton = 1
else
RECT win,0,0,100,100,RGB(0,0,80),RGB(0,0,80)
recton = 0
endif
case 2
' deal with timer 2
if circleon = 0
CIRCLE win,300,250,100, RGB(255,0,0),RGB(0,255,0)
circleon = 1
else
CIRCLE win,300,250,100, RGB(0,0,80),RGB(0,0,80)
circleon = 0
endif
endselect
ENDSELECT
return
endsub


Bit boring, but hey ..  :)

(I notice the 'code' flags seem to be ignoring code layout tabs  )   ::)

Graham
Tomorrow may be too late ..

Techno

Thanks

When do you use "start the timer with an callback" ?

1.) I prefer this manner is easy I think

'Start a timer that sends @IDTIMER messages.
CONST TIMER_1 = 1
STARTTIMER hWnd, 5000, TIMER_1

2.) When do you use this manner?
'Start a timer with a callback
STARTTIMER hWnd, 1000, TIMER_1, &cb_timer

Can you please give me an short example when they use timer with callback?


barry

Take a look in the program Lines.eba.

On line 26, which is in the beginning or housekeeping portion of the program, you see the command STARTIMER win,10.  That tells Windows to send a timer message to the handler for the window win every 10 milliseconds.

Then, on line 44 in the callback SUB mainwindow it responds to the @IDTIMER message.  This is the message sent to the window every 10 milliseconds.

Then on line 40 in that same callback function it has a case to respond to the @IDCLOSEWINDOW message and there it issues a STOPTIMER win command that tells windows to stop sending the timer to the window.  My guess (I probably should know this but I don't) is that if this isn't done Windows will continue to send the message even after the program closes.  In older, less carefully monitored OS's than Windows, this could crash the system if it happened, although i doubt that would happen with Windows.

So basically what happens is that at the start of the program, it tells Windows that the window win is gonna need to be notified every 10 milliseconds so it can do something, in this case, draw a line.  Then the callback function includes some code to watch for that notification and respond to it.  When it receives the notification in the form of an @IDTIMER message, it does what it has to do.  This happens every 10 milliseconds.  Then, before the program closes, it tells Windows to stop sending these notices.

It's fairly simple in concept but not as simple to explain.

Here's a little pretend example but don't try to execute this.  It's just for illustration.


' Do all the miscellaneious stuff you have to do at the start of a program

OPENWINDOW win, etc

' The window has been created so tell windows to send an @IDTIMER message
' every 10 milliseconds to the handler for win

STARTIMER win, 10

run = 1

' wait here till the window closes to close the program
WAITUNTIL win = 0 | run = 0
end

' then in the callback you have this

CASE @IDTIMER
    ' Windows sent a timer notice so do whatever it is you want to do every 10 milliseconds

CASE @IDCLOSEWINDOW
    ' The window win closing so stop the timer before it closes
    STOPTIMER win

    ' the timer is stopped so now close the window
    CLOSEWINDOW win


GWS

The callback option is just an alternative method.

Either you deal with the @idtimer messages in the main window message handling subroutine - or you write a separate subroutine to deal with what happens when the timer 'fires'.

Whichever method you prefer ..  :)

Here's the above example using the callback method:


window win
int style, run, recton, circleon

style = @MINBOX|@MAXBOX|@SIZE
OPENWINDOW win,0,0,600,400,style,0,"Timer Example",&winh
setwindowcolor win,rgb(0,0,80)

' start a 1 second timer
starttimer win,1000,1,&timing1
' start a 2 second timer
starttimer win,2000,2,&timing2

run = 1

WAITUNTIL run = 0
' before closing stop any timers used ..
stoptimer win,1
stoptimer win,1
closewindow win
END

SUB winh
SELECT @CLASS
case @IDCLOSEWINDOW
run = 0
ENDSELECT
return
endsub

sub timing1
' deal with timer 1
if recton = 0
RECT win,0,0,100,100,RGB(255,0,0),RGB(0,0,255)
recton = 1
else
RECT win,0,0,100,100,RGB(0,0,80),RGB(0,0,80)
recton = 0
endif

return
endsub

sub timing2
' deal with timer 2
if circleon = 0
CIRCLE win,300,250,100, RGB(255,0,0),RGB(0,255,0)
circleon = 1
else
CIRCLE win,300,250,100, RGB(0,0,80),RGB(0,0,80)
circleon = 0
endif
return
endsub


Graham
Tomorrow may be too late ..