Time programs

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Nicky
Posts: 17
Joined: Sep 22, 2008 0:47

Time programs

Post by Nicky »

Anyway got any time programs? Heres one I written.

Code: Select all

Declare Function TickCount () AS Integer

Dim MillSec AS Integer
Dim Seconds AS Integer
Dim Minutes AS Integer
Dim Hours AS Integer
Dim Days AS Integer
Dim Weeks AS Integer

ScreenRes 800, 600

While 1

MillSec = (TickCount()   )
Seconds = (MillSec / 1000) 
Minutes = (Seconds / 60  )
Hours   = (Minutes / 60  )
Days    = (Hours   / 24  )
Weeks   = (Days    / 7   )

ScreenLock
CLS
Print"Your computers been on ..."
Print
Print"Weeks:" & Weeks
Print"Days:" & Days Mod 7
Print"Hours:" & Hours Mod 24
Print"Minutes:" & Minutes Mod 60
Print"Seconds:" & Seconds Mod 60
Print"MillSeconds:" & MillSec Mod 1000
ScreenUnlock 

Wend

Function TickCount () AS Integer
Return Timer * 1000
End Function 
- Nicky
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

Nice - I would suggest adding a sleep 1 statement in your loop to reduce CPU usage and to also add some means to exit the program.

Example

Code: Select all

Declare Function TickCount () As Integer

Dim MillSec As Integer
Dim Seconds As Integer
Dim Minutes As Integer
Dim Hours As Integer
Dim Days As Integer
Dim Weeks As Integer

ScreenRes 800, 600
cls
Print"Your computers been on ..."
Print
Print"      Weeks:" 
Print"       Days:"  
Print"      Hours:"  
Print"    Minutes:"  
Print"    Seconds:"  
Print"MillSeconds:" 
do

MillSec = (TickCount()   )
Seconds = (MillSec / 1000) 
Minutes = (Seconds / 60  )
Hours   = (Minutes / 60  )
Days    = (Hours   / 24  )
Weeks   = (Days    / 7   )
 
locate 3,15
Print using "##"; Weeks
locate ,14
Print using "###";Days Mod 7
locate ,15
Print using "##";Hours Mod 24
locate ,15
Print using "##"; Minutes Mod 60
locate ,15
Print using "##"; Seconds Mod 60
locate ,14
Print using "###"; MillSec Mod 1000
 
sleep 1
loop until inkey$=chr$(27)

Function TickCount () As Integer
Return Timer * 1000
End Function 
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

here's another example of your timer for the fun of it -

Code: Select all

'original code from Nicky
'Modified by phishguy
'compile with -s gui


Declare Function TickCount () As Integer

Dim MillSec As Integer
Dim Seconds As Integer
Dim Minutes As Integer
Dim Hours As Integer
Dim Days As Integer
Dim Weeks As Integer
Dim As Integer x = 1,y = 1
Dim As Single t
Dim As Integer MAX_X, MAX_Y,oldsec
Screeninfo MAX_X, MAX_Y
Screenres Max_x,Max_y,8,,&h10 Or &h20
Color 4
t = Timer
Do
    
    MillSec = (TickCount()   )
    Seconds = (MillSec / 1000) 
    Minutes = (Seconds / 60  )
    Hours   = (Minutes / 60  )
    Days    = (Hours   / 24  )
    Weeks   = (Days    / 7   )
    
    If oldsec <> seconds Then
        oldsec = seconds
        Cls
        Screenlock
        Draw String (x,y+1),"Your computers been on ..."
        Draw String (x,y+11),"      Weeks:" & Str(weeks)
        Draw String (x,y+21),"       Days:"  & Str(days Mod 7)
        Draw String (x,y+31),"      Hours:"  & Str(hours Mod 24)
        Draw String (x,y+41),"    Minutes:" & Str(minutes Mod 60) 
        Draw String (x,y+51),"    Seconds:" & Str(seconds Mod 60) 
        Screenunlock
    End If
    
    If Timer - t > 5 Then
        x = Rnd * (Max_x - 170) 
        y = Rnd * (max_y - 60)
        t = Timer
    End If
    
    Sleep 5,0
Loop Until Inkey$=Chr$(27)

Function TickCount () As Integer
    Return Timer * 1000
    End Function 
Nicky
Posts: 17
Joined: Sep 22, 2008 0:47

Post by Nicky »

Are they anyway to define the "Mod" to '%'? This don't work:

#define % Mod

I'm use to '%' from previous programming langauge.

By the way nice add ons to my program!
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

Are they anyway to define the "Mod" to '%'? This don't work:
No. % is used as a literal suffix to define an integer number.
Post Reply