SheanHoxie Posted July 8, 2011 Share Posted July 8, 2011 (edited) I am reading from an INI and then after performing my tasks I try to delete the section from the INI. I cant seem to figure out how to delete a section, then read the INI and then delete another section and so on. My INI: [class.07.08.2011.1700] room=b classLength=30 cueLength=55000 instructorFirst=Liana instructorLast=Liana className=Express_ABS [class.07.08.2011.1730] room=b classLength=30 cueLength=55000 instructorFirst=Elena instructorLast=Elena className=Booty_Beat And My AutoIt script: expandcollapse popup$IniSource = @DesktopDir & "\Autoit Scripts\classSchedule.ini" ;Get section names from INI source. Section names are class.MM.DD.YY.HHMM $sections = IniReadSectionNames($IniSource) If @error Then MsgBox(4096, "", "Error occurred with IniReadSectionNames.") Else ; count sections $sectionsLength = UBound($sections) - 1 EndIf ; check if $sections array contains anything If $sectionsLength > 1 Then ; setup infinite loop so we keep checking class schedules $classLoop = 0 While $classLoop == 0 ;loop through array to get schedule times For $i = 1 To $sections[0] ;Get now time to compare to schedule times $nowTime = "class." & @MON & "." & @MDAY & "." & @YEAR & "." & @HOUR & @MIN ;Get Hour and MIN for future check against late/early starting classes (TODO) $nowHour = @HOUR $nowMin = @MIN $endTime = "" & $endHour & $endMin & "" ;MsgBox(4096, "", $endTime, 2) ;If the time matches a class time If $nowTime == $sections[$i] Then MsgBox(4096, "", $sections[$i], 1) ;Get the room letter that will be live. Default to room x so we can issue error if x $classRoom = IniRead($IniSource, $sections[$i], "room", "x") ;Get the length of class minutes $classLength = IniRead($IniSource, $sections[$i], "classLength", "60") $iCueLength = IniRead($IniSource, $sections[$i], "cueLength", "60000") $sInstructorFirst = IniRead($IniSource, $sections[$i], "instructorFirst", "a") $sInstructorLast = IniRead($IniSource, $sections[$i], "instructorLast", "b") $sClassName= IniRead($IniSource, $sections[$i], "className", "c") If @error Then MsgBox(4096, "IniRead Error", "IniRead encountered an error line 50 schedule-ini.au3", 3) Else ; If no error in IniRead then initiate _RecordClass function _RecordClass($classRoom, $classLength, $sections[$i], $iCueLength, $sClassName, $sInstructorFirst, $sInstructorLast) ; Delete recording class from IniSource IniDelete($IniSource, $sections[$i]) If @error Then MsgBox(4096, "IniDelete Error", "Ini Delete encountered an error line 55 schedule-ini.au3") EndIf _ClassEmail($sections[$i]) EndIf EndIf Next ;Sleep for 10 seconds between searching for classes in .ini Sleep (10000) $updatedSections = IniReadSectionNames($IniSource) $updatedSectionsLength = UBound($updatedSections) - 1 If $updatedSectionsLength < 2 Then ;If no more class schedule end loop $classLoop = 1 EndIf WEnd EndIf Exit I'm a complete noob with AutoIt and so I know there is probably A LOT going wrong here. Any help is appreciated! Edited July 8, 2011 by SheanHoxie Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 8, 2011 Share Posted July 8, 2011 See IniDelete in the Helpfile. That, and a loop, should do what you need. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 8, 2011 Share Posted July 8, 2011 IniDelete() without a "key" parameter, see help file. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
SheanHoxie Posted July 8, 2011 Author Share Posted July 8, 2011 IniDelete() without a "key" parameter, see help file.Thanks for your help. I'm trying to delete the whole section, not just the key. I've gone through the IniDelete in the help file a few times, but I will go through again, maybe I'm missing something obvious Link to comment Share on other sites More sharing options...
SheanHoxie Posted July 8, 2011 Author Share Posted July 8, 2011 (edited) So I've reread the IniDelete() in the help file, and I think that I have it correct. I think the problem is actually within my loop what I am passing to $section[$i] isn't being updated properly. Here is how my brain is working: Getting the INI and reading it... $IniSource = @DesktopDir & "\Autoit Scripts\classSchedule.ini" $sections = IniReadSectionNames($IniSource) Since INI section name is class.MM.DD.YYYY.HHMM set a var with right nows time and date... $nowTime = "class." & @MON & "." & @MDAY & "." & @YEAR & "." & @HOUR & @MIN If it matches, do stuff... If $nowTime == $sections[$i] Then ; ; Do Stuff ; ; Then Delete the $section[$i] IniDelete($IniSource, $sections[$i]) EndIf So far, this works if I only have 1 section. If I have multiple sections, after I delete the first section, it fails to delete any other sections. I think that I am missing something when I loop that fails to replace the $sections[$i] variable, but it will loop through ok and perform all functions perfectly except the IniDelete() portion. Again, thanks for any help. Edited July 8, 2011 by SheanHoxie Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 8, 2011 Moderators Share Posted July 8, 2011 SheanHoxie,You are specifying the $nowTime to the minute, which is pretty limiting - how many of your ini sections are you expecting to match? You need to post your script and a representative ini file so that we can see how you loop through the elements of the $sections array. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 8, 2011 Share Posted July 8, 2011 If you have it in a For..Next loop like this, it should work. $IniSource = @DesktopDir & "\Autoit Scripts\classSchedule.ini" $sections = IniReadSectionNames($IniSource) For $i = 1 To $sections[0] If $nowTime = $sections[$i] Then ; ; Do Stuff ; ; Then Delete the $section[$i] IniDelete($IniSource, $sections[$i]) EndIf Next - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. 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