DATE issues (solved) but BUG uncovered!

Just starting out? Need help? Post your questions and find answers here.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

DATE issues (solved) but BUG uncovered!

Post 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$
Last edited by Rook Zimbabwe on Wed May 02, 2007 3:39 am, edited 1 time in total.
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post 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
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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.
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post 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
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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...
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Very strange, no idea why, perhaps, if no-one else can explain it, you should post it as a bug.
Clutch
User
User
Posts: 52
Joined: Sun Nov 26, 2006 6:11 am
Location: South Florida

Post 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
"Ahead one third... ahead two thirds... Full ahead flank
And out from the belly of the whale came a prophet, Amen"
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Of course, well spotted. That's the sort of bug that keep's me busy for hours. :oops:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I also hate those type of bugs. :twisted: Not even "EnableExplicit" will help.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

PB wrote:I also hate those type of bugs. :twisted: Not even "EnableExplicit" will help.
Me three. :)


Well spotted.
Dare2 cut down to size
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Clutch
User
User
Posts: 52
Joined: Sun Nov 26, 2006 6:11 am
Location: South Florida

Post 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. :)
"Ahead one third... ahead two thirds... Full ahead flank
And out from the belly of the whale came a prophet, Amen"
Post Reply