Author Topic: "time" command?  (Read 3273 times)

0 Members and 1 Guest are viewing this topic.

Frankolinox

  • Guest
"time" command?
« on: July 10, 2013, 04:48:13 AM »
how to set a "TIME" command?

my effort looks like that one:

Code: [Select]
'
' TIME 'how to set a TIME command ?
'

basic

%SYSTEMTIME_DEFINED = 1
TYPE SYSTEMTIME
   wYear         as word     '(sys)
   wMonth        as word     
   wDayOfWeek    as word     
   wDay          as word     
   wHour         as word     
   wMinute       as word     
   wSecond       as word   
   wMilliseconds as word   
END TYPE

DECLARE SUB GetSystemTime LIB "KERNEL32.DLL" ALIAS "GetSystemTime" ( _
   BYREF lpSystemTime AS systemtime _
 )                                   
dim mytime as systemtime

print "Es ist jetzt " & str(GetSystemTime(mytime)) & " Uhr." '9487292 ' for example
print "It's now " & str(GetSystemTime(mytime)) & " o'clock."

'
'strptr doesn't work
'
'Dim t as string = time
'print "Es ist jetzt " + t + " Uhr."
'

best regards, frank

Charles Pegge

  • Guest
Re: "time" command?
« Reply #1 on: July 10, 2013, 07:52:41 AM »
Hi Frank,

Simple example:

'http://msdn.microsoft.com/en-us/library/windows/desktop/ms724390(v=vs.85).aspx

type SYSTEMTIME
  word wYear
  word wMonth
  word wDayOfWeek
  word wDay
  word wHour
  word wMinute
  word wSecond
  word wMilliseconds
end type


! GetSystemTime lib "kernel32.dll" (SYSTEMTIME*lpSystemTime)

SYSTEMTIME t
GetSystemTime t
print t.wYear "." t.wMonth "." t.wDay " " t.wHour ":" t.wMinute ":" t.wSecond

Peter

  • Guest
Re: "time" command?
« Reply #2 on: July 10, 2013, 08:38:05 AM »
Peter's example:
Code: [Select]
include "sw.inc"
Window 640,480,1

Type SYSTEMTIME
     word wYear 
     word wMonth
     word wDayOfWeek
     word wDay   
     word wHour   
     word wMinute
     word wSecond
     word wMilliseconds
End Type

Declare GetSystemTime LIB "KERNEL32.DLL" ( SYSTEMTIME *lpSystemTime )
Declare GetLocalTime  Lib "kernel32.dll" ( ByRef lpSystemTime As SYSTEMTIME )

SYSTEMTIME t

while Key(27)=0
Cls RGB(255,255,255)

GetLocalTime t
Text 40,0,"Everything at a glance",sw_blue
Text 40, 40, "Datum " + t.wDay + "." + t.wMonth + "." + t.wYear,0
Text 40, 60, "Tag der Woche " + t.wDayOfWeek,0
Text 40, 80, "Zeit " + t.wHour + "." + t.wMinute + "." + t.wSecond,0

Sync
wend
Quit

Frankolinox

  • Guest
Re: "time" command?
« Reply #3 on: July 11, 2013, 01:57:44 AM »
thank you both for help, looks quite simple as so often in oxygen :-)

btw two another little questions:

do you have an idea charles how to convert "restore" (freebasic) with something like an "array" for oxygen?

more help is welcome too ;)

best regards, frank
« Last Edit: July 11, 2013, 08:39:36 AM by Frankolinox »

JRS

  • Guest
Re: "time" command?
« Reply #4 on: July 11, 2013, 09:17:51 AM »
How would OxygenBasic emulate the NOW (seconds past Jan. 1, 1970) function we see in other variations of BASIC?

Charles Pegge

  • Guest
Re: "time" command?
« Reply #5 on: July 11, 2013, 10:25:57 PM »
Time since 1970:

There is an OS function and a recipe to get this value, if anyone needs it.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx

Charles Pegge

  • Guest
Re: "time" command?
« Reply #6 on: July 11, 2013, 10:41:11 PM »
Data / Restore / Read:

These are not implemented in OxygenBasic but there are a number of ways to read data into an array.

This is good for moderate amounts of data:

type mydatatype
  string name
  int      n
  single  x,y
end type

mydatatype d[20]={
"shoes",2,100,100,
"socks",2,100,150,
"tie",1,100,170}

i=2
print d[ i ].name "  " d[ i ].n "  " d[ i ].x "," d[ i ].y



JRS

  • Guest
Re: "time" command?
« Reply #7 on: July 11, 2013, 11:26:11 PM »
Code: [Select]
FILETIME fTime = /*initialize file time*/;

//large int from fTime
ULARGE_INTEGER inftime;
inftime.LowPart = fTime.dwLowDateTime;
inftime.HighPart = fTime.dwHighDateTime;

//Large int init to the first second of jan 1 1970
SYSTEMTIME jan1970 = { 1970, 1, 4,1,0,0,0,0};
FILETIME ftjan1970;
SystemTimeToFileTime(&jan1970, &ftjan1970);
ULARGE_INTEGER largejan1970;
largejan1970.LowPart = ftjan1970.dwLowDateTime;
largejan1970.HighPart = ftjan1970.dwHighDateTime;

//shift from 1601 to 1970
__time64_t value100NS = inftime.QuadPart - largejan1970.QuadPart;

//convert from 100 nanosecond intervals to seconds
__time64_t result = value100NS / 10000000;

Why does Microsoft make everything look so ugly?

<MS Programmer> Here is the code you asked me to write boss.

<MS Boss> This looks great and is very efficient. Give it to production to add their NOOP bloat layers and wrappers so no one would ever guess how simple this was in the beginning.


Frankolinox

  • Guest
Re: restore question + "time" command?
« Reply #8 on: July 12, 2013, 03:17:08 AM »
thanks charles for your restore/data help and that's running here :)

but... I have this code extract and I am not sure how to convert in correct way

Code: [Select]
'
' fictive code example
'

type myFrankoDatatype
  string name
  int      n
  single  x,y
end type

myFrankoDatatype d[10]={
"hl23000000",2,100,100,
"h234000010",2,100,150,
"hw2013",1,100,170}
"thor",2,100,250
"prometheus",2,100,350}

string abcd
sys test,ma

myFrankoHeader:

'------------------------------ how to convert that one? ------
data "hl23000000"   
data "h234000010"   
data "hw2013"
data "thor"
data "prometheus"
data "here's the end!"
'------------------------------ how to convert that one? ------

if test then
restore myFrankoHeader : abcd=read 'getfile
ma=instr(abcd,"+")
'... more code lines
end if

best regards, frank and sunny warm day to the north

Charles Pegge

  • Guest
Re: "time" command?
« Reply #9 on: July 12, 2013, 05:33:52 AM »
No need for read and restore. Execute this initialiser code first before the rest of the program.


myFrankoHeader:

...
'------------------------------ how to convert that one? ------
string sd[6]={
  "hl23000000",    
  "h234000010",  
  "hw2013",
  "thor",
  "prometheus",
  "here's the end!"}
'------------------------------ how to convert that one? ------

'arrays d and sd are ready for use