kiwichick Posted December 21, 2013 Posted December 21, 2013 Hi there, I'm very new to AutoIt and still pretty much a newbie at scripting in general. I really only discovered scripting after I started using XYplorer as my file manager and began using and making xys scripts to do the usual automation things. Then I started making a script that displays Astrological information (including Zodiac sign) based on an entered date of birth. But the problem with xys scripting is that XYplorer itself is required to run the script - it can't be compiled to an independent exe like an AutoIt script can. I realised it would be a real pain to have to open XYplorer every time I wanted to use the script and I wouldn't be able to share it with anyone else unless they had XYplorer installed. So I've started converting the script (very slowly) to AutoIt but I have no idea how to format the date of birth into the Zodiac sign. With xys scripting it can be done automatically using the "formatdate" command which has a "Zodiac" format option. In my script the date of birth is entered via 3 dropdown menus (day, month, year) and the results are passed into a single variable - so I use the following xys code to format the results: $sign = formatdate("$date", "Zodiac"); Obviously, it is extremely handy with the xys command doing all the hard work but I have no idea how to do calculate the Zodiac date using AutoIt. If anyone is able to help I would be very very grateful :-) Cheers.
markyrocks Posted December 21, 2013 Posted December 21, 2013 i wrote this for you. its not thoroughly tested but it seems to work expandcollapse popup#include <GUIConstantsEx.au3> #Include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <Array.au3> Gui() Func Gui() GUICreate("zodiac",400,300) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE") GUICtrlCreateLabel("Enter Your Birthday",150,100) Global $input = GUICtrlCreateInput("mm/dd/yyyy",150,150) Global $button = GUICtrlCreateButton("GO",150,200) EndFunc while 1 $msg = GUIGetMsg() Select Case $msg = $button ;~ MsgBox("","","button pressed....") Global $input1 = GUICtrlRead($input) ;~ MsgBox("","",$input1) Calculate($input1) Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd func Close() Exit EndFunc func Calculate($input1) $sString = StringSplit($input1,"/") ;sString[0] is meaningless so is sString[3], [1]=mm [2]=dd if $sString[1] = 1 and $sString >= 21 Then MsgBox("","result","You are Aquarious!") elseif $sString[1] = 1 and $sString[2] <= 20 Then MsgBox("","result","You are Capricorn!") elseif $sString[1] = 2 and $sString[2] <= 19 Then MsgBox("","result","You are Aquarious!") elseif $sString[1] = 2 and $sString[2] >= 20 Then MsgBox("","result","You are Pisces!") elseif $sString[1] = 3 and $sString[2] <= 20 Then MsgBox("","result","You are Pisces!") elseif $sString[1] = 3 and $sString[2] >= 21 Then MsgBox("","result","You are Aries!") elseif $sString[1] = 4 and $sString[2] <= 20 Then MsgBox("","result","You are Aries!") elseif $sString[1] = 4 and $sString[2] >= 21 Then MsgBox("","result","You are Taures!") elseif $sString[1] = 5 and $sString[2] <= 21 Then MsgBox("","result","You are Taures!") elseif $sString[1] = 5 and $sString[2] >= 22 Then MsgBox("","result","You are Gemini!") elseif $sString[1] = 6 and $sString[2] <= 21 Then MsgBox("","result","You are Gemini!") elseif $sString[1] = 6 and $sString[2] >= 22 Then MsgBox("","result","You are Cancer!") elseif $sString[1] = 7 and $sString[2] <= 23 Then MsgBox("","result","You are Cancer!") elseif $sString[1] = 7 and $sString[2] >= 24 Then MsgBox("","result","You are Leo!") elseif $sString[1] = 8 and $sString[2] <= 23 Then MsgBox("","result","You are Leo!") elseif $sString[1] = 8 and $sString[2] >= 24 Then MsgBox("","result","You are Virgo!") elseif $sString[1] = 9 and $sString[2] <= 23 Then MsgBox("","result","You are Virgo!") elseif $sString[1] = 9 and $sString[2] >= 24 Then MsgBox("","result","You are Libra!") elseif $sString[1] = 10 and $sString[2] <= 23 Then MsgBox("","result","You are Libra!") elseif $sString[1] = 10 and $sString[2] >= 24 Then MsgBox("","result","You are Scorpio!") ; hey im a scorpio elseif $sString[1] = 11 and $sString[2] <= 22 Then MsgBox("","result","You are Scorpio!") elseif $sString[1] = 11 and $sString[2] >= 23 Then MsgBox("","result","You are Sagittarius!") elseif $sString[1] = 12 and $sString[2] <= 21 Then MsgBox("","result","You are Sagittarius!") elseif $sString[1] = 12 and $sString[2] >= 22 Then MsgBox("","result","You are Capricorn!") EndIf Exit EndFunc Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
kiwichick Posted December 21, 2013 Author Posted December 21, 2013 Thank you so much markyrocks!! That works fabulously :-)
mikell Posted December 21, 2013 Posted December 21, 2013 (edited) For the fun... expandcollapse popup$gui = GuiCreate("zodiac", 200, 200) $datebox = GUICtrlCreateDate("", 10, 10, 120, 20) GUICtrlSendMsg($datebox, 0x1032, 0, "MM/dd/yyyy") ;$DTM_SETFORMAT_ = 0x1032 $label_sign = GuiCtrlCreateLabel("", 20, 60, 80, 20) GUICtrlSetFont(-1, 12, 400, 0, "Arial Unicode MS") $label_icon = GuiCtrlCreateLabel("", 100, 40, 60, 50) GUICtrlSetFont(-1, 36, 400, 0, "Arial Unicode MS") GuiSetState() While 1 $msg = GuiGetMsg() Switch $msg Case -3 Exit Case $datebox $result = _GetSign(GuiCtrlRead($datebox)) GuiCtrlSetData($label_sign, $result[0]) GuiCtrlSetData($label_icon, $result[1]) EndSwitch Wend Func _GetSign($date) Local $split = StringSplit($date, "/") Local $res[2], $n = Number($split[1] & $split[2]) Local $array[13][3] = [ _ [0101, "Capricorn", ChrW(9809)], _ [0121, "Aquarius", ChrW(9810)], _ [0220, "Pisces", ChrW(9811)], _ [0321, "Aries", ChrW(9800)], _ [0420, "Taurus", ChrW(9801)], _ [0521, "Gemini", ChrW(9802)], _ [0622, "Cancer", ChrW(9803)], _ [0723, "Leo", ChrW(9804)], _ [0824, "Virgo", ChrW(9805)], _ [0923, "Libra", ChrW(9806)], _ [1023, "Scorpio", ChrW(9807)], _ [1123, "Sagittarius", ChrW(9808)], _ [1222, "Capricorn", ChrW(9809)]] For $i = 0 To 12 If $n >= $array[$i][0] Then $res[0] = $array[$i][1] $res[1] = $array[$i][2] EndIf Next Return $res EndFunc Edited December 21, 2013 by mikell
kiwichick Posted December 21, 2013 Author Posted December 21, 2013 Oh mikell, That's awesome Because I live in New Zealand, I use a different date format - dd/mm/yyyy. So what would I need to change in the code? I changed this line: GUICtrlSendMsg($datebox, 0x1032, 0, "MM/dd/yyyy") ;$DTM_SETFORMAT_ = 0x1032 to this: GUICtrlSendMsg($datebox, 0x1032, 0, "dd/MM/yyyy") ;$DTM_SETFORMAT_ = 0x1032 And the calendar date displays correctly but the script processes it as MM/dd/yyyy and I get the wrong sign as a result. Obviously I also need to change something else but I don't know enough about AutoIt yet to see what it is. Thanks for your patience.
kiwichick Posted December 21, 2013 Author Posted December 21, 2013 So I feel quite clever now. I have changed this line: Local $res[2], $n = Number($split[1] & $split[2]) to this: Local $res[2], $n = Number($split[2] & $split[1]) And now it behaves as expected I would still like to know if this is what I should have done and is there anything else I still need to do?
mikell Posted December 21, 2013 Posted December 21, 2013 Nothing else... you did exactly the 2 modifications that were to be done Congrats
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now