TIME$

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
User avatar
stilgar
Newbie
Posts:5
Joined:Thu Jun 12, 2008 3:42 am
Location:Michigan, USA
Contact:
TIME$

Post by stilgar » Thu Jun 12, 2008 3:57 am

Hello all,
How do I split apart TIME$ so I can save it as 3 variables?

thank you.

pebe
Full Member
Posts:33
Joined:Tue Apr 02, 2002 12:19 am
Location:Scotland

Post by pebe » Thu Jun 12, 2008 7:39 am

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

User avatar
stilgar
Newbie
Posts:5
Joined:Thu Jun 12, 2008 3:42 am
Location:Michigan, USA
Contact:

Post by stilgar » Thu Jun 12, 2008 12:44 pm

Thank you.
I knew it was simple, I did it many years ago, and just couldn't remeber.

Dragoncat
Newbie
Posts:5
Joined:Wed Jul 30, 2008 7:06 pm
Contact:

Splitting time$ into three parts...

Post by Dragoncat » Wed Jul 30, 2008 7:26 pm

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!

Dragoncat
Newbie
Posts:5
Joined:Wed Jul 30, 2008 7:06 pm
Contact:

Post by Dragoncat » Sun Nov 09, 2008 6:43 am

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....

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

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

Post by Valerie » Wed Nov 12, 2008 10:24 am

:cry: That's a lot of coding...........

pebe
Full Member
Posts:33
Joined:Tue Apr 02, 2002 12:19 am
Location:Scotland

Post by pebe » Mon Nov 24, 2008 7:07 pm

Here's an even simpler version.

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

Harry Potter
Jr. Member
Posts:10
Joined:Sat Feb 14, 2009 3:26 pm
Location:New York, U.S.

TIME$

Post by Harry Potter » Sat Feb 14, 2009 3:40 pm

It is a good idea to set another variable to TIME$ so that it doesn't change while parsing. Just a hint. :)

Post Reply