Page 1 of 1

DATE issues (solved) but BUG uncovered!

Posted: Mon Apr 30, 2007 6:25 am
by Rook Zimbabwe
I am having a problem returning the specific seconds froma date... I want to know the seconds of a specific date at 23:59:59 but I can't get the compiler to cooperate. This may be a bug in VAL... does anyone know???

Code: Select all

plotz1$ = FormatDate("%yyyy", Date())
plotz2$ = FormatDate("%mm", Date())
plotz3$ = FormatDate("%dd", Date())
plotz4$ = "23"
plotz5$ = "59"
plotz6$ = "59"

plotzo$=plotz1$+plotz2$+plotz3$+plotz4$+plotz5$+plotz6$
Debug plotzo$

puz.l=Val(plotzo$)
Debug puz.l

dayo.l=Date() ; what I really want to do is throw the number 
              ; from puz into Date() To Return the secs of that date!

dayo.l = dayo.l + 1  ; ADD 1 to make it midnight

today$=Str(dayo.l) ; then use it
debug "TODAY: "+today$

Posted: Mon Apr 30, 2007 8:17 am
by walker
you're trying to write a value > 2147483647 into a long...

change

Code: Select all


puz.l=Val(plotzo$)
Debug puz.l
into

Code: Select all


puz.q=ValQ(plotzo$)
Debug puz.q
and your debug output is what you'd expected... :D

Posted: Mon Apr 30, 2007 9:28 am
by Derek
From the help,

Code: Select all

Date = Date([Year, Month, Day, Hour, Minute, Second])
Why not just put the date you want and the time you want into the date() command.

Posted: Mon Apr 30, 2007 10:56 am
by Baldrick
maybe this will help?

Code: Select all

Repeat 
timer=ElapsedMilliseconds()
If timecounter+1000<timer
 timecounter=timer
 count+1

dayo.l=Date()
Debug "Normal time > "+FormatDate("%yyyy - %mm - %dd <> %hh:%ii:%ss",dayo)
dayo+1 ; 1 second added
Yr=Year(dayo)
day=Day(dayo)
month=Month(dayo)
hr=Hour(dayo)
min=Minute(dayo)
sec=Second(dayo)
Debug "1 second fast > "+Str(yr)+"-" +Str(month)+"-"+ Str(day)+"<>"+  Str(hr)+ ":"+Str(min)+":"+ Str(sec )
EndIf 
Until count>60

Posted: Mon Apr 30, 2007 11:19 am
by Derek
Try this as well

Code: Select all

OpenWindow(0,0,0,200,240,"",$ca0001)
CreateGadgetList(WindowID(0))
CalendarGadget(0,10,10,180,160)
TextGadget(1,10,180,180,20,"",#PB_Text_Border|#PB_Text_Center)
TextGadget(2,10,210,180,20,"",#PB_Text_Border|#PB_Text_Center)
Repeat
  e=WaitWindowEvent()
  If e=#PB_Event_Gadget
    If EventGadget()=0
      d=GetGadgetState(0)

      y=Val(FormatDate("%yyyy",d))
      m=Val(FormatDate("%mm",d))
      d=Val(FormatDate("%dd",d))
      h=Val(FormatDate("%hh",d))
      i=Val(FormatDate("%ii",d))
      s=Val(FormatDate("%ss",d))

      SetGadgetText(1,"Clicked date : "+Str(Date(y,m,d,h,i,s)))
      SetGadgetText(2,"+ 23:59:59: "+Str(Date(y,m,d,23,59,59)))

    EndIf
  EndIf
Until e=16
Edit. You can use the Year(), Month() etc functions like Baldrick has, I just used the formatdate() command to fit in with the first bit of code.

Posted: Mon Apr 30, 2007 3:30 pm
by Rook Zimbabwe
All suggestions are helpful... Derek Bender yours is fantastic for what I want it to do!

Code: Select all

      SetGadgetText(1,"Clicked date : "+Str(Date(y,m,d,h,i,s))) 
      SetGadgetText(2,"+ 23:59:59: "+Str(Date(y,m,d,00,00,00))) 
Is what I used, now what date you click on the calendar is working for me fine... I can use all the other date functions fromthe calendar click. Year, month, day, day of week, etc.

Thanks all!!!
:D

Posted: Mon Apr 30, 2007 3:35 pm
by Rook Zimbabwe
Hey look at this...

Code: Select all

OpenWindow(0,0,0,200,240,"",$ca0001) 
CreateGadgetList(WindowID(0)) 
CalendarGadget(0,10,10,180,160) 
TextGadget(1,10,180,180,20,"",#PB_Text_Border|#PB_Text_Center) 
TextGadget(2,10,210,180,20,"",#PB_Text_Border|#PB_Text_Center) 
Repeat 
  e=WaitWindowEvent() 
  If e=#PB_Event_Gadget 
    If EventGadget()=0 
      d=GetGadgetState(0) 

      y=Val(FormatDate("%yyyy",d)) 
      m=Val(FormatDate("%mm",d)) 
      d=Val(FormatDate("%dd",d)) 
      h=Val(FormatDate("%hh",d)) 
      i=Val(FormatDate("%ii",d)) 
      s=Val(FormatDate("%ss",d)) 

      SetGadgetText(1,"Clicked date : "+Str(Date(y,m,d,h,i,s))) 
      SetGadgetText(2,"+ 00:00:00: "+Str(Date(y,m,d,00,00,00))) 

    EndIf 
  EndIf 
Until e=16
There is a difference by what dateis clicked on the calendar... and the difference depends on what day is clicked...

I went to JAN 2007 and clicked on day 1 and it was 1 sec off... day 3 is 3 secs off... day 31 is 31 secs off...

Posted: Mon Apr 30, 2007 10:27 pm
by Derek
Very strange, no idea why, perhaps, if no-one else can explain it, you should post it as a bug.

Posted: Mon Apr 30, 2007 10:53 pm
by Clutch
The problem is that the variable 'd' is first used to store the value of the selected date, then it is used almost immediately after to store the day value of that date. The subsequent calls to get values for 'h', 'i', and 's' are then going to be incorrect. See the following:

Code: Select all

OpenWindow(0,0,0,200,240,"",$ca0001) 
CreateGadgetList(WindowID(0)) 
CalendarGadget(0,10,10,180,160) 
TextGadget(1,10,180,180,20,"",#PB_Text_Border|#PB_Text_Center) 
TextGadget(2,10,210,180,20,"",#PB_Text_Border|#PB_Text_Center) 
Repeat 
  e=WaitWindowEvent() 
  If e=#PB_Event_Gadget 
    If EventGadget()=0 
      date=GetGadgetState(0)            ; <- Changed from 'd' to 'date' 
                                        ;  |
      y=Val(FormatDate("%yyyy",date))   ; <-
      m=Val(FormatDate("%mm",date))     ; <-
      d=Val(FormatDate("%dd",date))     ; <-
      h=Val(FormatDate("%hh",date))     ; <-
      i=Val(FormatDate("%ii",date))     ; <-
      s=Val(FormatDate("%ss",date))     ; <-

      SetGadgetText(1,"Clicked date : "+Str(Date(y,m,d,h,i,s))) 
      SetGadgetText(2,"+ 00:00:00: "+Str(Date(y,m,d,00,00,00))) 

    EndIf 
  EndIf 
Until e=16

Posted: Tue May 01, 2007 10:32 am
by Derek
Of course, well spotted. That's the sort of bug that keep's me busy for hours. :oops:

Posted: Tue May 01, 2007 11:01 am
by PB
I also hate those type of bugs. :twisted: Not even "EnableExplicit" will help.

Posted: Tue May 01, 2007 11:10 am
by Dare
PB wrote:I also hate those type of bugs. :twisted: Not even "EnableExplicit" will help.
Me three. :)


Well spotted.

Posted: Wed May 02, 2007 4:58 am
by Rook Zimbabwe
Yepper... the lesson here kiddies is: Use unique variable names every time!!!
and keep track of them with comments and notes like yer Uncle Rook!

Great Spot Clutch... Thats why you are so cool you program with shades! 8)

Posted: Wed May 02, 2007 6:03 pm
by Clutch
PB's debugger and variable viewer get the credit on this one. I looked at and ran that snip four or five times throughout the day and didn't see the bug until I set a breakpoint and did some steppin'. Self-explanatory variable names are your friend. :)