Page 1 of 1

TIME$

Posted: Thu Jun 12, 2008 3:57 am
by stilgar
Hello all,
How do I split apart TIME$ so I can save it as 3 variables?

thank you.

Posted: Thu Jun 12, 2008 7:39 am
by pebe
t$=time$
hour$=left$(t$,2)
min$=mid$(t$,4,2)
sec$=right$(t$,2)

Posted: Thu Jun 12, 2008 12:44 pm
by stilgar
Thank you.
I knew it was simple, I did it many years ago, and just couldn't remeber.

Splitting time$ into three parts...

Posted: Wed Jul 30, 2008 7:26 pm
by Dragoncat
or.... Why not simply use Mid$???
You can get all three parts just using that one alone
and better yet you can do it in a loop... and place the output into an array of strings, in one easy step...
the advantage?? the whole set of related time sets of characters are neatly sored away into a single object...
rather than three... dim an array of type string * how ever long each "piece" is:
the piece size for each time variable is n% here
rem $DYNAMIC
n%= ....
dim array(n%) as string *2
and dim it to 2 (normal defualt for arrays is to start from 0)
then use a mid$ with a variable , but be sure to add one to the variable used with the mid$ after making any other necessary adjustments, then loop some variable
for x% = 0 to 2
b% = x% + 1
array(x%)=mid$(time$,b%,n%)
next x%
program has to be started with the /ah /cmd $dynamic metacomand in order to work , otherwise It will not like the above dim command
This will also work for stripping ANY string into predefined segments.. I hope you enjoy!

Posted: Sun Nov 09, 2008 6:43 am
by Dragoncat
Here is the program I just wrote that splits time very nicely into three parts and puts them into an array...
DECLARE SUB gorp ()
DIM SHARED array(2) AS STRING * 2
CALL gorp
PRINT array(0)
PRINT array(1)
PRINT array(2)

------ this part here gets created as a SUBROUTINE call:
SUB gorp
SHARED array() AS STRING * 2
r$ = TIME$
n% = 2
FOR x% = 0 TO 2
b% = 3 * x% + 1
array(x%) = MID$(r$, b%, n%)
NEXT x%
END SUB
hope this helps....

Mmmm...............

Posted: Wed Nov 12, 2008 10:24 am
by Valerie
:cry: That's a lot of coding...........

Posted: Mon Nov 24, 2008 7:07 pm
by pebe
Here's an even simpler version.

hour$=left$(TIME$,2)
min$=mid$(TIME$,4,2)
sec$=right$(TIME$,2)

TIME$

Posted: Sat Feb 14, 2009 3:40 pm
by Harry Potter
It is a good idea to set another variable to TIME$ so that it doesn't change while parsing. Just a hint. :)