Jump to content

My $variables aren't coming through, have a made a wrong 'case' statement?


timmyc
 Share

Go to solution Solved by jdelaney,

Recommended Posts

Hi All,

Im setting up something that starts with a GUI with 3 radio buttons (shift1,shift2 and shift3) 

Depending on what radio button (shift) you select will determine the times of that shift. The night shift (shift3) will finish on a different date than it starts so i have made a separate variable for that

The issue im having is that $d (which should change based on the radio button) is not coming through when i call on it later on in the script.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_2 = GUICreate("Date/Time Changer", 503, 331, 192, 132)
$shift1 = GUICtrlCreateRadio("Day Shift", 32, 120, 137, 25)
$shift2 = GUICtrlCreateRadio("Arvo Shift", 30, 158, 137, 25)
$shift3 = GUICtrlCreateRadio("Night shift", 30, 198, 137, 25)
$HPOV = GUICtrlCreateLabel("HPOV Date Changer", 104, 16, 330, 52)
GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
$Go = GUICtrlCreateButton("Go", 288, 264, 153, 33)
$date1 = GUICtrlCreateInput("DD/MM/14", 216, 72, 137, 24)
$Startlabel = GUICtrlCreateLabel("Starting Date", 112, 80, 89, 20)
$Finlabel = GUICtrlCreateLabel("Finishing Date     (For Night Shift only)", 168, 200, 113, 36)
$date2 = GUICtrlCreateInput("DD/MM/14", 288, 200, 137, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $start, $finish, $shift1, $shift2, $shift3, $dateme, $d

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
  Exit
Case $Go
if GUICtrlRead($shift1) then $start = "08:30"
 if GUICtrlRead($shift1) then $finish = "15:00"
If GUICtrlRead($shift1) Then $d = $date1


  if GUICtrlRead($shift2) then $start = "15:00"
  if GUICtrlRead($shift2) then $finish = "23:30"
 If GUICtrlRead($shift2) Then $d = $date1


if GUICtrlRead($shift3) then $start = "23:30"
if GUICtrlRead($shift3) then $finish = "09:00"
  If GUICtrlRead($shift3) Then $d = $date2


runjob ()
EndSwitch
WEnd

 



Can anyone have a look at the above and make sure it is formatted correctly.

Thanks
Tim

Edited by timmyc
Link to comment
Share on other sites

The night shift always ends startdate + 1 day? So you could always calculate the end date yourself for shift 3. You would avoid typos etc.

Check the example script for GUICtrlCreateRadio to see how to check for a checked radio.

Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED




			
		

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

here you go

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_2 = GUICreate("Date/Time Changer", 503, 331, 192, 132)
$shift1 = GUICtrlCreateRadio("Day Shift", 32, 120, 137, 25)
$shift2 = GUICtrlCreateRadio("Arvo Shift", 30, 158, 137, 25)
$shift3 = GUICtrlCreateRadio("Night shift", 30, 198, 137, 25)
$HPOV = GUICtrlCreateLabel("HPOV Date Changer", 104, 16, 330, 52)
GUICtrlSetFont(-1, 20, 800, 0, "Times New Roman")
$Go = GUICtrlCreateButton("Go", 288, 264, 153, 33)
$date1 = GUICtrlCreateInput("DD/MM/14", 216, 72, 137, 24)
$Startlabel = GUICtrlCreateLabel("Starting Date", 112, 80, 89, 20)
$Finlabel = GUICtrlCreateLabel("Finishing Date     (For Night Shift only)", 168, 200, 113, 36)
$date2 = GUICtrlCreateInput("DD/MM/14", 288, 200, 137, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $start, $finish, $shift1, $shift2, $shift3, $dateme, $d

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
  Exit
Case $Go
    $bContinue = True
    If GUICtrlRead($shift1)=1 Then
        $start = "08:30"
        $finish = "15:00"
        $d = $date1
    ElseIf GUICtrlRead($shift2)=1 Then
        $start = "15:00"
        $finish = "23:30"
        $d = $date1
    ElseIf GUICtrlRead($shift3)=1 Then
        $start = "23:30"
        $finish = "09:00"
        $d = $date2
    Else
        $start = ""
        $finish = ""
        $d = ""
        MsgBox(1,1,"No shift selected")
        $bContinue = False
    EndIf
    MsgBox(1,1, $start & @CRLF & $finish & @CRLF & $d)
    If $bContinue Then runjob ()

EndSwitch
WEnd
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks alot jdelaney!

...hmm only thing is when i use your script the message box that should pop up and show me the variables is pulling $start $finish fine but not $d, it just says that $d = 8, also when the script continues and dumps the values in a field it comes out as 8.

Any idea what would be causing that?

Edited by timmyc
Link to comment
Share on other sites

Ah, I just worked on the switch.  You would need to guictrlread those 'dates'.

$d = guictrlread($date2)

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...