12 Replies - 1140 Views - Last Post: 18 February 2010 - 12:51 AM Rate Topic: -----

#1 cub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-January 10

Can Someone Please explain what I'm Doing wrong..

Posted 04 February 2010 - 10:23 PM

I have dug into eveything I have to reference from to get this far and I still cannot make this do what I want it to do.

Please If you can explain what I am doing wrong I would appreciate it..

Sequence of events..

1. I input the time needed (lets say 4 hours)
2. I capture system time as the start time
3. I capture system time as the stop time
4. At this point I call Partycal()
5. I modify the system time to work with it to find the remaining time left compared to the needed time.

At least I have tried to do..

6. Then I display the remaining hours and secs using what you see below.

Let's say that the needed time is 4 hours

Everytime I try to make provisons for a situation to where the remaining time is at let's say 3:01 getting ready to go to 2:59 I can't get it to 2 without screwing it all up and nothing works.

My goal is when I grab the stop time and it is lets say 30 mins left that it displays the time left properly. and that if I stopped it anytime during the the 4 hours it displays properly.

Am I doing something wrong or what..

I have left everything as is so you can tell I am new at this..


Private Sub Command14_Click()
  
    Label22.Caption = TimeValue(Now)
   
   STOPHOURS = Label22.Caption
   STARTH = Label9.Caption
   HOURSNDED = Label31.Caption

  Call PARTYCAL
 
  Label55.Caption = (REMAININGHOURS & ":" & REMAININGMINS)
  
End Sub



Public Sub PARTYCAL()
  
       
    STARTHOURS = Format((Val(Hour(STARTH))), "00") ' Start Hours
    STARTMINS = Format((Val(Minute(STARTH))), "00") 'Start Min
    
    STOPHOURSa = Format((Val(Hour(STOPHOURS))), "00") ' Stop Hrs
    STOPMINS = Format((Val(Minute(STOPHOURS))), "00") 'Stop Mins
     
    
    
    If STARTHOURS <= STOPHOURSa And STARTMINS < STOPMINS Then
        ELAPSEDHOURS = HOURSNDED - 1
        ELAPSEDMINS = 60 - (STOPMINS - STARTMINS)
        End If
  
   'If STOPHOURSa = STARTHOURS And STARTMINS >= STOPMINS Then
      '  ELAPSEDHOURS = HOURSNDED
      '  ELAPSEDMINS = 1
      '  End If
       
   'If STOPHOURSa > STARTHOURS And STARTMINS < STOPMINS Then
      ' ELAPSEDHOURS = STOPHOURSa - STARTHOURS
      ' ELAPSEDMINS = 60 - (STOPMINS - STARTMINS)
      ' End If
    
  
     
     
     ' If ELAPSEDMINS = 0 Then
     ' REMAININGHOURS = ELAPSEDHOURS - 1
     '  End If
   
     REMAININGHOURS = ELAPSEDHOURS
     REMAININGMINS = ELAPSEDMINS
   
    
    'Label64.Caption = (ELAPSEDHOURS & ":" & ELAPSEDMINS)
    'Label55.Caption = (REMAININGHOURS & ":" & REMAININGMINS)
    

    
End Sub






Is This A Good Question/Topic? 0
  • +

Replies To: Can Someone Please explain what I'm Doing wrong..

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Can Someone Please explain what I'm Doing wrong..

Posted 05 February 2010 - 12:50 PM

hello dude :)
here is how to make a stop watch tutorial i think it will help you
http://www.dreaminco...wtopic95412.htm
tmrTime is the timer control select it form your components bar

or this snippet
http://www.dreaminco...e/snippet46.htm
good luck :)

This post has been edited by NoBrain: 05 February 2010 - 02:53 PM

Was This Post Helpful? 0
  • +
  • -

#3 cub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-January 10

Re: Can Someone Please explain what I'm Doing wrong..

Posted 05 February 2010 - 11:13 PM

Thanks NoBrain,

It is probably a true statement that trying to understand someones else's code is like relearning a language. At least That's what I've heard. I can understand why though.

All of the timer related answers and problems I have read about have dealt with either the current or elapsed time, or starting/stopping an event with at a certain time. None that I have come accross have dealt with the remaining time compared to a set time of hours/sec given.

This is the problem I have been trying to figure out. I am close, very close, because as it stands I can display the remaining time using system time. My problem is, and has always been understandng why the stored variable when it delivers the data to the label seems to be unusable or something..

It seems as though I cannot unload the variable with the code I have, to decrement the remaining time already displayed in the label.

I cannot find in any of the books I have that explains what is going on in a dim, public,private, etc variable as it is used in any program.

An Ex; would be declaring

Public MYTIME As String...or Integer

Then using this in a form more than once..Like first it delivers a 4 then it delivers a 5 to a specified object.

What I am experiencing is that the variable does not unload properly, or I'm not using it properly..

I thought that after the variable has been used once, it can be reloaded with new data, and so on..


sorry for any misunderstandings.
Was This Post Helpful? 0
  • +
  • -

#4 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Can Someone Please explain what I'm Doing wrong..

Posted 06 February 2010 - 05:58 AM

ok here is what i try
Private Sub Command1_Click()
    Do
    DoEvents
    Label1.Caption = Return_Time_Dif
    Loop While Time <> "15:53:00"
    MsgBox "Now Is The Time!!", vbExclamation
End Sub
Private Function Return_Time_Dif() As String
        Dim strTime1 As String
        Dim strTime2 As String
        Dim strTime2inMinutes As Double
        Dim strTime1inMinutes As Double
        Dim strTimeDiff As String
        
        
        strTime2 = "15:53:00"
        strTime1 = Time
        strTime1inMinutes = (Hour(strTime1) * 60 + Minute(strTime1) + Second(strTime1) / 60)
        strTime2inMinutes = (Hour(strTime2) * 60 + Minute(strTime2) + Second(strTime2) / 60)
        strTimeDiff = CStr(strTime2inMinutes - strTime1inMinutes)
        If InStr(1, strTimeDiff, ".") <> 0 Then
            strTimeDiff = TimeSerial(0, Round(strTimeDiff - 0.5, 0), Format(Mid(strTimeDiff, InStr(1, strTimeDiff, "."), Len(strTimeDiff)), "0.00") * 60)
        End If
        
        Return_Time_Dif = strTimeDiff
End Function




so it show in label1.caption the time that remain to the time we want (15:00:00) in my case. there is a few bugs i gues but that is the idea


good luck dude :)

This post has been edited by NoBrain: 06 February 2010 - 06:50 AM

Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: Can Someone Please explain what I'm Doing wrong..

Posted 06 February 2010 - 12:38 PM

View Postcub, on 04 February 2010 - 09:23 PM, said:

I have dug into eveything I have to reference from to get this far and I still cannot make this do what I want it to do.

Please If you can explain what I am doing wrong I would appreciate it..

Sequence of events..

1. I input the time needed (lets say 4 hours)
2. I capture system time as the start time
3. I capture system time as the stop time
4. At this point I call Partycal()
5. I modify the system time to work with it to find the remaining time left compared to the needed time.

At least I have tried to do..

6. Then I display the remaining hours and secs using what you see below.

Let's say that the needed time is 4 hours

Everytime I try to make provisons for a situation to where the remaining time is at let's say 3:01 getting ready to go to 2:59 I can't get it to 2 without screwing it all up and nothing works.

My goal is when I grab the stop time and it is lets say 30 mins left that it displays the time left properly. and that if I stopped it anytime during the the 4 hours it displays properly.

Am I doing something wrong or what..

I have left everything as is so you can tell I am new at this..


Private Sub Command14_Click()
  
    Label22.Caption = TimeValue(Now)
   
   STOPHOURS = Label22.Caption
   STARTH = Label9.Caption
   HOURSNDED = Label31.Caption

  Call PARTYCAL
 
  Label55.Caption = (REMAININGHOURS & ":" & REMAININGMINS)
  
End Sub



Public Sub PARTYCAL()
  
       
    STARTHOURS = Format((Val(Hour(STARTH))), "00") ' Start Hours
    STARTMINS = Format((Val(Minute(STARTH))), "00") 'Start Min
    
    STOPHOURSa = Format((Val(Hour(STOPHOURS))), "00") ' Stop Hrs
    STOPMINS = Format((Val(Minute(STOPHOURS))), "00") 'Stop Mins
     
    
    
    If STARTHOURS <= STOPHOURSa And STARTMINS < STOPMINS Then
        ELAPSEDHOURS = HOURSNDED - 1
        ELAPSEDMINS = 60 - (STOPMINS - STARTMINS)
        End If
  
   'If STOPHOURSa = STARTHOURS And STARTMINS >= STOPMINS Then
      '  ELAPSEDHOURS = HOURSNDED
      '  ELAPSEDMINS = 1
      '  End If
       
   'If STOPHOURSa > STARTHOURS And STARTMINS < STOPMINS Then
      ' ELAPSEDHOURS = STOPHOURSa - STARTHOURS
      ' ELAPSEDMINS = 60 - (STOPMINS - STARTMINS)
      ' End If
    
  
     
     
     ' If ELAPSEDMINS = 0 Then
     ' REMAININGHOURS = ELAPSEDHOURS - 1
     '  End If
   
     REMAININGHOURS = ELAPSEDHOURS
     REMAININGMINS = ELAPSEDMINS
   
    
    'Label64.Caption = (ELAPSEDHOURS & ":" & ELAPSEDMINS)
    'Label55.Caption = (REMAININGHOURS & ":" & REMAININGMINS)
    

    
End Sub






yen when you deal with date and time consider always a specific functions for that

now let use consider a situation
when you start the watch at mid night stop it at one hour later
now check that is your code is right there

This post has been edited by thava: 06 February 2010 - 12:57 PM

Was This Post Helpful? 1
  • +
  • -

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Can Someone Please explain what I'm Doing wrong..

Posted 06 February 2010 - 12:52 PM

:)

This post has been edited by NoBrain: 06 February 2010 - 01:45 PM

Was This Post Helpful? 0
  • +
  • -

#7 cub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-January 10

Re: Can Someone Please explain what I'm Doing wrong..

Posted 10 February 2010 - 01:56 AM

Hi Gentlemen,

First and foremost, Thanks..

I want to simplify what I am doing..

1. A customer tells me that he/she want 10 hours of service.
2. So I start his time at 24:00/12:00am/00:00. (I hate this).
3. He comes back and tells me he has to stop.
4. I stop his time at 02:00.
5. So I can keep track of everyone I calculate the time remaining, which in
this case would be exactly 8 hours..

Before I explain my latest attempt to find remaining time, I would like help understanding the Val() and TimeSerial() functions. I am using these trying to solve my problem.

MyTime As String

In a statement like Mytime = Val(TheCapturedTime), is MyTime a String or an Integer?

Likewise: In a Statement like

MyTime = TimeSerial(TheCapturedTimeHours,TheCapturedTimeMin,TheCapturedTimeSec), is MyTime a string, Date, or Integer?

In the later: I find the elapsed time and subtract it from the Needed time that I have
put the TimeSerial() like this , TimeSerial(HoursNeeded, "00", "00"), zero's in variables.
I did this to put the single hour into a time format.


Thava/NoBrains: I think problems arise as one would go from 24:00 to 01:00..this would not be a factor if not for the pm/am that would arise sometimes..

Ex; Hours needed = 5 starttime = 23:00 and then stopping 3 hours later at 02:00 , and the start time was lets say 01:00 the day before.

Hope you can understand!!


Now to explain my latest attempt on how I am trying to find remaining time.
Please try this putting in diff numbers and see what you think.

"Some code is unused" Add commandClick() and 2 labels to form..




Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
Dim StartHr As Integer
Dim StartMinute As Integer
Dim StartSecond As Integer

Dim StopHr2 As Integer
Dim StopMinute2 As Integer
Dim StopSecond2 As Integer

Dim dtmNewTime As Date
Dim dtmNewTime2 As Date

Dim dtmNewTime3 As Date
Dim Interval As Integer
Dim Needed As Integer
Dim Left As Integer
Dim TEST4 As Integer


StartHour = 1
StartMinute = 0
StartSecond = 0


StopHour2 = 23
StopMinute2 = 34
StopSecond2 = 0

Needed = 20
Interval = 12


dtmNewTime = TimeSerial(StartHour, StartMinute, StartSecond)
dtmNewTime2 = TimeSerial(StopHour2, StopMinute2, StopSecond2)
Label1.Caption = dtmNewTime & " " & dtmNewTime2

dtmNewTime3 = TimeSerial(StartHour, StartMinute, StartSecond) - TimeSerial(StopHour2, StopMinute2, StopSecond2)
Label2.Caption = dtmNewTime3

If Val(dtmNewTime3) < Needed Then
Left = Needed - Val(dtmNewTime3)
MsgBox "yes " & Left
Else
MsgBox "no " & Left
Left = 0
End If

Label3.Caption = Left


End Sub

Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Can Someone Please explain what I'm Doing wrong..

Posted 11 February 2010 - 06:02 AM

hello :)
sorry for the late reply. take a look at that code
    Dim strHour As String
    Dim strMinutes1 As String
    Dim strMinutes2 As String
    Dim strSeconds As String
    Dim strResult As String
    Dim strDays As String
    strMinutes1 = (1440 + Hour(dDate1) * 60 + Minute(dDate1) + Second(dDate1) / 60)
    strMinutes2 = (Hour(dDate2) * 60 + Minute(dDate2) + Second(dDate2) / 60)
    strResult = strMinutes1 - strMinutes2
    strResult = TimeSerial(0, Round(strResult - 0.5, 0), Format(mID(strResult, InStr(1, strResult, "."), Len(strResult)), "0.00") * 60)
    strMinutes = Minute(strResult)
    strHour = Hour(strResult)
    strSeconds = Second(strResult)
    If Not strDays = 0 Then
        strHour = strHour + (strDays - 1) * 24
    End If
    strResult = Format(strHour, "00") & ":" & Format(strMinutes, "00") & ":" & Format(strSeconds, "00")




i will explain it latter i am at work right now :)
Was This Post Helpful? 0
  • +
  • -

#9 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: Can Someone Please explain what I'm Doing wrong..

Posted 11 February 2010 - 08:04 PM

i told you that use the common funcitons
i change your code a little bit will solve your requirement

dtmNewTime = TimeSerial(starthour, StartMinute, StartSecond)
dtmNewTime2 = TimeSerial(stophour2, StopMinute2, StopSecond2)
Label1.Caption = dtmNewTime & " " & dtmNewTime2
'****************This is the code Added by me********************'
If starthour > stophour2 Then
dtmNewTime2 = DateAdd("d", 1, dtmNewTime2)
End If

'dtmNewTime3 = TimeSerial(starthour, StartMinute, StartSecond) - TimeSerial(stophour2, StopMinute2, StopSecond2)'

dtmNewTime3 = dtmNewTime2 - dtmNewTime
'****************This is the code Added by me********************'
Label2.Caption = dtmNewTime3



hope you understand, what i try to say?

This post has been edited by thava: 11 February 2010 - 08:05 PM

Was This Post Helpful? 1
  • +
  • -

#10 cub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-January 10

Re: Can Someone Please explain what I'm Doing wrong..

Posted 12 February 2010 - 10:36 PM

Thanks Fellows,

Give me a bit to read and fully understand both your posts.

What I have now works. However, It looks like a rambling road..NOOB!!

I found that I will have a problem if the running time passes the 24:00/12:00 mark, Still thinking about this. And the answer may lie in your posts. Wont know til I read and understand them.

So I will return in about a day..Thanks for staying with me on this project of mine..
I'm learning more than just coding..
Cub
Was This Post Helpful? 0
  • +
  • -

#11 cub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-January 10

Re: Can Someone Please explain what I'm Doing wrong..

Posted 14 February 2010 - 07:49 PM

Hello again,

Well I did try your code Thava and it seems to have solved the problem. I Dug into DateAdd, something I did not want to mess with because I am a noob, but totally understand why the code works. I was unaware of the Interval incrementing/decrementing the given serial time depending on +/- Interval given. NEAT..Thank you sir..

I believe that will do it..I will have to do a real time test to see if it passes unharmed..

I also tried yours, NoBrain and you will definitely have to explain every detail, because I am lost with it..
I tried adjusting

""strResult = TimeSerial(0, Round(strResult - 0.5, 0), Format(mID(strResult, InStr(1, strResult, "."), Len(strResult)), "0.00") * 60)"",,

I'm sure it is a simple thing but I just can't see it..

I did use Now() for dDate1 and DateAdd("d",1,dDate1) for dDate2..

But was unable to make it work..Also, I did not know how to handle the StrDays = 0..Sorry

I would like to understand it if you would explain it to me..


I wanted to show you both what the project looks like so here a snap of it, below..

I still have some things to complete but getting there..



Posted Image

This post has been edited by cub: 14 February 2010 - 08:18 PM

Was This Post Helpful? 0
  • +
  • -

#12 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: Can Someone Please explain what I'm Doing wrong..

Posted 16 February 2010 - 05:41 AM

SURELY MY CODE(YOUR CODE) WILL WORK CORRECTLY UNTILL THE INTERVAL IS STRICTLY LESS THAN 24
OTHER WISE THERE IS SOME PROBLEM SO YOU NEED TO MODIFY SOME PART OF THE CODE
Was This Post Helpful? 1
  • +
  • -

#13 cub  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-January 10

Re: Can Someone Please explain what I'm Doing wrong..

Posted 18 February 2010 - 12:51 AM

Hi Thava,

The modifications you did to the code was correct. (Please Read My Post)

I did find the problem with both 24:00 and 12:00..

I can't think of any situation that system would be in the negative..

At present my program is working perfectly..

Now if the program encounters 24:00/12:00 in the middle of time a day is added and time adjusted properly. Since the day not an issue the time is adjusted and the day incremented.

I have yet to have some friends beta test it for me, but I have put it through some rigorous testing to prove the functions.

At Present, the program receives data from the user and the times are recorded.
While a customer/client is in his time frame a green light is displayed for the users quick reference.
As soon as the user stops time all events are finished and a red light indicates to user that persons time is stopped.
If, while the users time is running the user inadvertently tries to re-enter data a msg displays telling him this and giving him the option of cancelng the msg and returning to run or clearing the member out for a new client/cust entry.

In addition, at stop time a file is written with that clients data and once the first data is written continues to append any new times stopped with the clients data.

Also, I have included your name as a contributor to this free program, but can remove it if you don't want it listed this way. I felt that was needed since your code simplified things greatly and I learned a lot..Thanks

Cub
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1