|
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 |
1. help with additional 2 time$ and convert #3717 |
Hello... i want to additionnal 2 time$ for example : it's 21H30 on my pc...., if i add 1H00 so it's 22H30... but... if i add 4H45... it make 25H95... and it's wrong naturally.... i must convert to time format....for make 2H15 morning... thanks for helping...sometimes..if you are best solution for additionnal 2 time$...i take..;-) if you are code source on website... thanks for advance |
2. Re: help with additional 2 time$ and convert #3719 Posted by: 2004-04-04 05:39:38 |
use MOD on the calculated time. If you have the time x and add y then use the formula z = ( y + x ) MOD 24
|
3. Re: help with additional 2 time$ and convert #3720 |
oki i attempt this... i say you if i can make it thanks for response |
4. Re: help with additional 2 time$ and convert #3721 |
arf i dont can realize.... i put my exemple source ...:
$include "rapidq.inc" declare sub convert
CREATE Form AS QFORM Caption = "Form1" Width = 270 Height = 384 Center CREATE Edit1 AS QEDIT Text = time$ Left = 36 Top = 35 END CREATE CREATE Button1 AS QBUTTON Caption = "convert" Left = 83 Top = 127 TabOrder = 1 onclick=convert END CREATE CREATE Edit2 AS QEDIT Text = "add hours here" Left = 42 Top = 68 TabOrder = 2 END CREATE create edit3 as qedit Text = "" Left = 42 Top = 227 TabOrder = 3 END CREATE END CREATE
sub convert test1=val(edit1.text) test2=val(edit2.text) edit3.text= str$(test1+test2)mod 24 end sub
Form.ShowModal
'---------------------cut here------------------
so onshowmodal, i 've pc time on edit1.... i want to calculate whats hours if i add 2 hours for example on edit2.... i put btn and result on edit3.text....
very thanks......for advance.. |
5. Re: help with additional 2 time$ and convert #3723 |
Try timestamp.bas: http://g.yi.org/f.php?f=5772#7278 |
6. Re: help with additional 2 time$ and convert #3727 |
thanks guidance... i see it |
7. Re: help with additional 2 time$ and convert #3732 |
hi... i'm very sorry, but i can't make this ... i'm so new in RQ for make it... My problem begin that (2:00:00 + 2:00:00=4:00:00) --> i can't make this correctly.... and x=(2:00:00 +23:0:00)MOD 24 don't run properly..
i'm sorry i'm happy if you can help me with tim$ pb lol
thanks |
8. Re: help with additional 2 time$ and convert #3735 Posted by: 2004-04-05 06:09:18 |
Dear Maoulida,
time is a bugger to do calculations on as the seconds and minutes are limited to 60 and hours are limited to 12 or 24. There are two ways to make your program work; one is to let the user enter two times as two pieces of text and analysing those, the other is to split the input up into hours, minutes and seconds.
The program below uses the second method;
Declare sub Bereken (sender as QButton)
DIM Form AS QFORM Form.Caption = " Time calculator" Form.Width = 320 Form.Height = 300 Form.font.name = "Arial" Form.font.size = 16 Form.Center
Dim Labels(6) as QLabel Dim Edits(9) as QEdit for x=1 to 3 tp = x*40 : if x>2 then tp = tp + 60 for y=1 to 2 z=x*2+y-2 Labels(z).parent = form Labels(z).width = 80 Labels(z).left = y * 50 + 40 Labels(z).top = tp Labels(z).caption = ":" next y for y=1 to 3 z=x*3+y-3 Edits(z).parent = form Edits(z).width = 34 Edits(z).left = y * 50 Edits(z).top = tp Edits(z).text = " " next y next x
DIM Button AS QBUTTON Button.parent = Form Button.Caption = "Add times" Button.Left = 60 Button.Top = 125 Button.width = 120 Button.height = 40 Button.OnClick = Bereken
Form.ShowModal
Sub Bereken (sender as QButton) plmin = 0 : plhrs = 0 sec1 = val(Edits(3).text) sec2 = val(Edits(6).text) min1 = val(Edits(2).text) min2 = val(Edits(5).text) hrs1 = val(Edits(1).text) hrs2 = val(Edits(4).text) secs = sec1+sec2 Edits(9).text = str$(secs mod 60) if secs>59 then plmin = int(secs/60) mins = min1+min2+plmin Edits(8).text = str$(mins mod 60) if mins>59 then plhrs = int(mins/60) hrss = hrs1+hrs2+plhrs Edits(7).text = str$(hrss mod 12) end sub
As you can see it uses the MOD command ( not that it limits to a 12 hours maximum) to get the seconds, minutes and hours correct and a rounded (INT) division to get the 'carried over' minutes and hours.
You might want to add a second button that resets the Edits (clears them) to the proggy ;) |
9. Re: help with additional 2 time$ and convert #3736 Posted by: 2004-04-05 06:19:46 |
the other way is to take the time as a text string and analyze that; for the system clock this is easy as it is a set format; add the following lines to the above program just ahead of the DIM Button as QButton line;
Edits(1).text = left$(Time$,2) Edits(2).text = mid$(Time$,4,2) Edits(3).text = right$(Time$,2)
this will put the current system time (the time at which the program is run) in the top time space(s).
It is rather harder to analyze a user-input text as the length is not fixed; a time like 12:30:30 is obviously different in length and : placement to 1:6:5 and so extracting the desired time from an input like that is HARD to do right. It would involve looking for the : (or any other dividing symbol) in the entered text string and then cutting the string up. |
10. Re: help with additional 2 time$ and convert #3744 Posted by: cajino 2004-04-05 14:54:43 |
It is rather harder to analyze a user-input text as the length is not fixed; a time like 12:30:30 is obviously different in length and : placement to 1:6:5 and so extracting the desired time from an input like that is HARD to do right. It would involve looking for the : (or any other dividing symbol) in the entered text string and then cutting the string up.
This can be done with the Field$ function to overcome the non-fixed length problem. Bye
Cajino |
11. Re: help with additional 2 time$ and convert #3745 |
Baardaap...... very,very thanks!!!! its great code for me,i can learn how to work with time now.... very thanks!!
maoulidaZx@hotmail.com |
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 |