Diana (Cda) Posted February 6, 2009 Share Posted February 6, 2009 (edited) The DAT file in question is in simple text with this type of structure (9999 means repeats each year):"4/2/9999=BD: Cousin" "6/2/2009=Calendar entry"Was wondering if AI could read this info somehow as it does ini files with IniRead, so that on the current day, i.e., the 2nd entry above, AI would then launch the desktop calendar. Then on days with no entries, the script would not launch the program. Example, text is entered for February 7th and 9th into the calendar program so that DAT file looks something like this: "7/2/2009=Calendar entry" "9/2/2009=Another entry" then tomorrow and on the 9th, the script would launch the program so that it appears on the desktop but wouldn't on the 8th of February when there is no entry. Is something like this possible? IniRead is what I know would be used for INI files but wondering how to deal with a DAT format. Edited February 7, 2009 by Diana (Cda) Link to comment Share on other sites More sharing options...
BrettF Posted February 6, 2009 Share Posted February 6, 2009 Normal file reading and its not to hard to make a 2D array like so if you split it line for line and parse it... $ar[n][0] = Date $ar[n][1] = Entry Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Malkey Posted February 6, 2009 Share Posted February 6, 2009 (edited) The DAT file in question is in simple text with this type of structure (9999 means repeats each year):"4/2/9999=BD: Cousin" "6/2/2009=Calendar entry"Was wondering if AI could read this info somehow as it does ini files with IniRead, so that on the current day, i.e., the 2nd entry above, AI would then launch the desktop calendar. Then on days with no entries, the script would not launch the program. Example, text is entered for February 7th and 9th into the calendar program so that DAT file looks something like this: "7/2/2009=Calendar entry" "9/2/2009=Another entry" then tomorrow and on the 9th, the script would launch the program so that it appears on the desktop but wouldn't on the 8th of February when there is no entry. Is something like this possible? IniRead is what I know would be used for INI files but wondering how to deal with a DAT format.Using this "DatFile.Dat" file. 4/2/9999=BD: Cousin 6/2/2009=Calendar entry 27/12/2009=Calendar entry 7/02/2009=Another entry This script appears to work. #include <Array.au3> $sFile = "DatFile.Dat" If StringLen(@MDAY) = 2 And StringLeft(@MDAY, 1) = 0 Then $iDay = StringTrimLeft(@MDAY, 1) Else $iDay = @MDAY EndIf If StringLen(@MON) = 2 And StringLeft(@MON, 1) = 0 Then $iMon = StringTrimLeft(@MON, 1) Else $iMon = @MON EndIf $sToDay = $iDay & "/" & $iMon & "/" & @YEAR ;MsgBox(0, "", $sToDay) $aToDay = StringSplit($sToDay, "/") $sRE = "((?:\d*" & $aToDay[1] & "/\d*" & $aToDay[2] & "/" & $aToDay[3] & ")|(?:" & _ "\d*" & $aToDay[1] & "/\d*" & $aToDay[2] & "/" & "9999))" If StringRegExp(FileRead($sFile), $sRE, 0) = 1 Then MsgBox(0, "", "Run( Desktop Calendar") Edited February 6, 2009 by Malkey Link to comment Share on other sites More sharing options...
Diana (Cda) Posted February 7, 2009 Author Share Posted February 7, 2009 Using this "DatFile.Dat" file. 4/2/9999=BD: Cousin 6/2/2009=Calendar entry 27/12/2009=Calendar entry 7/02/2009=Another entry This script appears to work. #include <Array.au3> $sFile = "DatFile.Dat" If StringLen(@MDAY) = 2 And StringLeft(@MDAY, 1) = 0 Then $iDay = StringTrimLeft(@MDAY, 1) Else $iDay = @MDAY EndIf If StringLen(@MON) = 2 And StringLeft(@MON, 1) = 0 Then $iMon = StringTrimLeft(@MON, 1) Else $iMon = @MON EndIf $sToDay = $iDay & "/" & $iMon & "/" & @YEAR ;MsgBox(0, "", $sToDay) $aToDay = StringSplit($sToDay, "/") $sRE = "((?:\d*" & $aToDay[1] & "/\d*" & $aToDay[2] & "/" & $aToDay[3] & ")|(?:" & _ "\d*" & $aToDay[1] & "/\d*" & $aToDay[2] & "/" & "9999))" If StringRegExp(FileRead($sFile), $sRE, 0) = 1 Then MsgBox(0, "", "Run( Desktop Calendar")Brilliant! So far, so good! It's worked extremely well through many tests! Of course, since I'm not a natural programmer or anything approaching even a proficient one yet, I formatted the code a little bit so that when I come back to it in the future, I'll be up to speed with it quicker:expandcollapse popup#include <Array.au3> ;====================== $sFile = "calendar.dat" ;====================== If NOT ProcessExists("Desktop Calendar.exe") Then _RunDesktopCalendar() Else Exit EndIf ;----------------------------------------------------------------------------------- Func _RunDesktopCalendar() If StringLen(@MDAY) = 2 And StringLeft(@MDAY, 1) = 0 Then $iDay = StringTrimLeft(@MDAY, 1) Else $iDay = @MDAY EndIf If StringLen(@MON) = 2 And StringLeft(@MON, 1) = 0 Then $iMon = StringTrimLeft(@MON, 1) Else $iMon = @MON EndIf $sToDay = $iDay & "/" & $iMon & "/" & @YEAR ;MsgBox(0, "", $sToDay) $aToDay = StringSplit($sToDay, "/") $sRE = "((?:\d*" & $aToDay[1] & "/\d*" & $aToDay[2] & "/" & $aToDay[3] & ")|(?:" & _ "\d*" & $aToDay[1] & "/\d*" & $aToDay[2] & "/" & "9999))" If StringRegExp(FileRead($sFile), $sRE, 0) = 1 Then ShellExecute(@ScriptDir & "\Desktop Calendar.exe") EndIf EndFunc ;-----------------------------------------------------------------------------------I don't really need the "not process exist" part since it'll be in the startup folder and won't start anyway unless the conditions are met, but put it in just in case I need to add a potential messagebox down the road. The code will be ready to go at that point. This script has made it possible to disable the app's native notification box that comes up when there is an event. Since this behaviour halts the actual launch process until you click OK, it turned out to be a cumbersome feature for me. I find that it's just better to have the calendar appear straight away on the desktop if, and only if, there is an event. At some point, I'll probably emulate that behaviour with AI so that it does display the actual event at the same time it's dumping it on the desktop since the boxes are actually rather small and larger amounts of text won't be very visible. But that's a project for later. This is super fantastic! Thanks! I'll also be putting a copy of the dat file along with this script in my AI tips folder. I suspect this will come in handy in future uses when dealing with a text file format that is not INI. Cheers! <g> Link to comment Share on other sites More sharing options...
Diana (Cda) Posted February 7, 2009 Author Share Posted February 7, 2009 Normal file reading and its not to hard to make a 2D array like so if you split it line for line and parse it... $ar[n][0] = Date $ar[n][1] = Entry Cheers, BrettThank you! Will keep this in mind for when I understand what you just said better <lol>. Bears looking into down the road, definitely. Cheers! <g> Link to comment Share on other sites More sharing options...
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