Problem converting one part of script to v2
Posted: 07 Apr 2024, 23:10
I have a script that I'm trying to convert to v2. It takes a date of birth and returns the corresponding astrological sign. I'm having a problem with the section of code that performs error checks for the entered dob. If I exclude that section of code, the script works (as long as a legitimate dob is entered). But when I include the error checking code, the script behaves as if the first error has occurred. For the life of me, I can't figure out how to fix it. Can someone please help me? To keep the script manageable, I have it in two files - the GUI is in one file, the code to split the dob and do the error checking is in the other. This also allows me to run the dob split file as a standalone script.
Code: Select all
#SingleInstance Force
#Include %A_ScriptDir%\docs
#Include ColorConstants_V2.ahk2
;TITLE FOR ALL WINDOWS
window_title := "DOBist"
;BACKGROUND IMAGES FOR INPUT AND OUTPUT WINDOWS
background_image1 := A_ScriptDir . "\images\backgrounds\background1.jpg"
background_image2 := A_ScriptDir . "\images\backgrounds\background2.jpg"
;CREATE INPUT GUI1 TO ENTER DOB
myGui := Gui()
myGui.Add("Picture", "x0 y0 w500 h500", background_image1)
myGui.SetFont("bold s14")
myGui.Add("Text", "x100 y200 w300 h25 +Center", "Please enter your date of birth")
myGui.BackColor := color_white
ogcEditdob_enter := myGui.Add("Edit", "x200 y235 w100 h30 -Multi +Center vdob_enter", "2/12/1965")
myGui.SetFont("bold s12")
ogcButtonGO := myGui.Add("Button", "x140 y275 w100 h25 +Center default", "GO")
ogcButtonGO.OnEvent("Click", lbGoButton.Bind("Normal"))
ogcButtonCLOSE := myGui.Add("Button", "x270 y275 w100 h25 +Center", "CLOSE")
ogcButtonCLOSE.OnEvent("Click", lbClose1Button.Bind("Normal"))
; GUI:
myGui.Title := window_title
myGui.Show("xCenter yCenter w500 h500")
return
lbClose1Button(A_GuiEvent, GuiCtrlObj, Info, *)
{ ; V1toV2: Added bracket
_1GuiClose:
_1GuiEscape:
ExitApp()
} ; V1toV2: Added bracket before function
lbGoButton(A_GuiEvent, GuiCtrlObj, Info, *)
{ ; V1toV2: Added bracket
oSaved := myGui.Submit()
dob_enter := oSaved.dob_enter
myGui.Destroy()
#Include dobsplit_V2.ahk2
MsgBox(sign)
ExitApp()
} ; V1toV2: Added bracket in the end
Code: Select all
; dob_enter := "2/12/1965" ; uncomment only when using as standalone
; ERROR CHECK DOB
if (dob_enter := "")
{
MsgBox("No date of birth was entered. Please re-enter your date of birth.")
Reload()
}
if (dob_enter := A_Space)
{
MsgBox("No date of birth was entered. Please re-enter your date of birth.")
Reload()
}
If (dob_enter := "dd/mm/yyyy")
{
MsgBox("No date of birth was entered. Please re-enter your date of birth.")
Reload()
}
If !InStr(dob_enter, "/")
{
MsgBox("An invalid date of birth was entered. Please re-enter your date of birth.")
Reload()
}
If (dob_enter ~= "i)(|||a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|\.||)")
{
MsgBox("An invalid date of birth was entered. Please re-enter your date of birth.")
Reload()
}
;SPLIT DOB_ENTER
dob_split := StrSplit(dob_enter,"/")
;CHECK YEAR HAS 4 NUMBERS
If (StrLen(dob_split[3]) != 4)
{
MsgBox("The year must have 4 numbers. Please re-enter your date of birth.")
Reload()
}
If (dob_split[1] ~= "^(?i:1|2|3|4|5|6|7|8|9)$")
dob_pad1 := 0 . dob_split[1]
else dob_pad1 := dob_split[1]
If (dob_split[2] ~= "^(?i:1|2|3|4|5|6|7|8|9)$")
dob_pad2 := 0 . dob_split[2]
else dob_pad2 := dob_split[2]
dob_final := dob_pad2 . "" . dob_pad1
If (dob_final >= 101 && dob_final <= 120)
sign := "Capricorn"
If (dob_final >= 121 && dob_final <= 218)
sign := "Aquarius"
If (dob_final >= 219 && dob_final <= 320)
sign := "Pisces"
If (dob_final >= 321 && dob_final <= 420)
sign := "Aries"
If (dob_final >= 421 && dob_final <= 521)
sign := "Taurus"
If (dob_final >= 522 && dob_final <= 621)
sign := "Gemini"
If (dob_final >= 622 && dob_final <= 723)
sign := "Cancer"
If (dob_final >= 724 && dob_final <= 823)
sign := "Leo"
If (dob_final >= 824 && dob_final <= 923)
sign := "Virgo"
If (dob_final >= 924 && dob_final <= 1023)
sign := "Libra"
If (dob_final >= 1024 && dob_final <= 1121)
sign := "Scorpio"
If (dob_final >= 1122 && dob_final <= 1221)
sign := "Sagittarius"
If (dob_final >= 1222 && dob_final <= 1231)
sign := "Capricorn"