[SOLVED] Cannot Revert DateGadget Time

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

[SOLVED] Cannot Revert DateGadget Time

Post by Randy Walker »

I run the code below and...
if I do OK on the "before selection",
change time to 6:00:00 and do OK,
"The 1st selection" shows correct 6:00:00 time, which is correct,
But Ok brings me to "Use Last selection" showing old 3:00:00 time. which is wrong.
I don't know why.
When I return to the gettime() procedure I want to see the same time I put in the previous visit.
I can't figure out why it keeps coming up with that 3:00:00 time.
Doesn't matter if I make t.q global or static -- I've tried both.

Code: Select all

Global t.q
Procedure gettime()
;  Static t.q
  If OpenWindow(0,wx,wy,100,160,"3amAlarm*",#WS_DLGFRAME)
    ButtonGadget   (100, 20, 109, 30, 24, "OK")
                                                                         ;
    If Hour(Date()) > 3
      day = Day(Date())+1
    Else
      day = Day(Date())
    EndIf
    year = Year(Date())
    month = Month(Date())
    If t = 0 ; first run haas no time value
    MessageRequester("before selection",FormatDate("%hh:%ii:%ss",t))
      t = Date(year,month,day,3,0,0)
    Else ; *SHOULD* Use Last selection
      Debug "Keep Old t"
      MessageRequester("Use Last selection",FormatDate("%hh:%ii:%ss",t))
      Debug FormatDate("%hh:%ii:%ss",t)
    EndIf
    ;t = 1737784800
    DateGadget(102, 30, 7, 90, 25, "", 0, #PB_Date_UpDown)
    SetGadgetState(102, t) ; or put t  ^ there and delete this line with same results.
    SetWindowLong_(GadgetID(102), #GWL_STYLE, GetWindowLong_(GadgetID(102), #GWL_STYLE) | #DTS_TIMEFORMAT)
    alarmTime$ = GetGadgetText(102)
    CheckBoxGadget (105,   30, 27, 60, 18, "Alarm")
    StringGadget   (107,   85, 67, 14, 13,trump$, #PB_String_Numeric|#PB_String_BorderLess|#ES_MULTILINE|#ES_AUTOVSCROLL|$10000000)
    ButtonGadget   (108,   54, 109, 36, 24, "Kill")
    SetGadgetColor(102, #PB_Gadget_BackColor, $DDF3FF)
    ;       SetGadgetColor(103, #PB_Gadget_BackColor, $DDF3FF)
    ;       SetGadgetColor(104, #PB_Gadget_BackColor, $DDF3FF)
    SendMessage_(GadgetID(102),#EM_SETLIMITTEXT,2,0)
    ;       SendMessage_(GadgetID(103),#EM_SETLIMITTEXT,2,0)
    ;       SendMessage_(GadgetID(104),#EM_SETLIMITTEXT,2,0)
    SendMessage_(GadgetID(107),#EM_SETLIMITTEXT,2,0)
  EndIf
  If Len(alarm$) = 0     ; **MILITARY** TIME ! ! !
    secflag = 1
    alarm = 1
   ; alarmh$="03:00:00"    ; Default is enabled at 3:00 AM -- hence the name "3amAlarm"
    alarmm$="00"    ; Default is enabled at 3:00 AM -- hence the name "3amAlarm"
    alarms$="00"    ; Default is enabled at 3:00 AM -- hence the name "3amAlarm"
  EndIf
  SetGadgetState(105, alarm)
  DisableGadget(102,alarm-1)
  HideWindow(0,0)
  SetActiveGadget(100)
  q.l=#False
  Repeat
    oldgadget = GetActiveGadget()
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Gadget  = EventGadget()
        Select Gadget
          Case 105  ; AlarmCheck
            alarm=GetGadgetState(105)
            DisableGadget(102,alarm-1)
            If alarm
              SetWindowTitle(0,"     3amAlarm*")
            Else
              SetWindowTitle(0,"     3amAlarm")
            EndIf
            SetActiveGadget(100)
          Case 106
            SetActiveGadget(100)
          Case 102  ; Hr|Mn|Sc
            If oldgadget <> Gadget ; Catch Caret relocation
              PostMessage_(GadgetID(Gadget),#EM_SETSEL,2,0)
            EndIf
          ; Case 110  ; Stump Skype - closewindow on it
          Case 100  ; OK
            q =100
          Case 108  ; Kill
            quit = #True
            q =108
          Case 110  ; OK
            If GetGadgetState(110)
              SetGadgetText(107,"00")
            EndIf
        EndSelect
      Case #WM_KEYDOWN
        Select EventwParam()
          Case #VK_RETURN ; watch for Tab refocus
            s$=GetGadgetText(oldgadget)
            k.l=FindString(s$,Chr(13)+Chr(10),1) ; Stop CR/LF Ding
            If k.l<>0  ; Was Enter pressed on the StringGadget?
              s$ = ReplaceString(s$,Chr(13)+Chr(10),"")
              SetGadgetText(oldgadget,s$) ; Yes, so remove CR+LF.
              ;PostMessage_(GadgetID(oldgadget), #EM_SETSEL, k.l-1, k.l-1)  ; Set cursor position back.
              WaitWindowEvent()
              Repeat : _mess = WindowEvent() : Until _mess = 0
            EndIf
            k.l=FindString(s$,Chr(13),1) ; Stop CR/LF Ding
            If k.l<>0  ; Was Enter pressed on the StringGadget?
              s$ = ReplaceString(s$,Chr(13),"")
              SetGadgetText(oldgadget,s$) ; Yes, so remove CR+LF.
              ;PostMessage_(GadgetID(oldgadget), #EM_SETSEL, k.l-1, k.l-1)  ; Set cursor position back.
              WaitWindowEvent()
              Repeat : _mess = WindowEvent() : Until _mess = 0
            EndIf
            SetGadgetText(oldgadget,s$) ; Yes, so remove CR+LF.
            Select oldgadget
              Case 102, 103
                PostMessage_(GadgetID(oldgadget),#EM_SETSEL,2,0)
              Case 104, 107
                oldgadget = 99
              Case 100
                q =100
            EndSelect
            SetActiveGadget(oldgadget)
            Debug s$
            Debug Len(s$)
        EndSelect
    EndSelect
  Until q.l
  q = Val(StringField(GetGadgetText(102),1,":"))
  If Hour(Date()) > q
    day = Day(Date())+1
  Else
    day = Day(Date())
  EndIf
  year = Year(Date())
  month = Month(Date())
  t = Date(year,month,day,q,0,0)
EndProcedure
gettime()
MessageRequester("The 1st selection",GetGadgetText(102))
gettime()
MessageRequester("The 2nd selection",GetGadgetText(102))
[EDIT] Sorry, I'm supposed to mention I was doing the above in PB version 6.12 LTS on Windows 11 Pro 23H2

I AM AN IDIOT OPERATOR. Just another one of my famous I/O errors. I failed to assign the new time value to the t.q variable, So I added code to the bottom just below the "next q.l" line, and that fixed it, ALMOST. DuHHH!! I still need to get the minutes and seconds in there for it to be complete. :oops:
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.