SixWingedFreak Posted April 11, 2008 Posted April 11, 2008 (edited) expandcollapse popupIf $LogOffExpendedBookmarks = 1 Then Debug("Checking bookmark status.") If $Bookmark = "1" And $Bookmark1Empty = 1 Then Debug("Logging off (bookmark 1 is empty).") Terminate() ElseIf $Bookmark = "2" And $Bookmark2Empty = 1 Then Debug("Logging off (bookmark 2 is empty).") Terminate() ElseIf $Bookmark = "3" And $Bookmark3Empty = 1 Then Debug("Logging off (bookmark 3 is empty).") Terminate() ElseIf $Bookmark = "4" And $Bookmark4Empty = 1 Then Debug("Logging off (bookmark 4 is empty).") Terminate() ElseIf $Bookmark = "5" And $Bookmark5Empty = 1 Then Debug("Logging off (bookmark 5 is empty).") Terminate() ElseIf $Bookmark = "6" And $Bookmark6Empty = 1 Then Debug("Logging off (bookmark 6 is empty).") Terminate() ElseIf $Bookmark = "7" And $Bookmark7Empty = 1 Then Debug("Logging off (bookmark 7 is empty).") Terminate() ElseIf $Bookmark = "8" And $Bookmark8Empty = 1 Then Debug("Logging off (bookmark 8 is empty).") Terminate() ElseIf $Bookmark = "9" And $Bookmark9Empty = 1 Then Debug("Logging off (bookmark 9 is empty).") Terminate() ElseIf $Bookmark = "10" And $Bookmark10Empty = 1 Then Debug("Logging off (bookmark 10 is empty).") Terminate() ElseIf $Bookmark = "Random" Then If $BookmarkAmount = 1 And _ $Bookmark1Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 2 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 3 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 4 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 5 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 6 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 7 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 8 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 And _ $Bookmark8Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 9 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 And _ $Bookmark8Empty = 1 And _ $Bookmark9Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 10 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 And _ $Bookmark8Empty = 1 And _ $Bookmark9Empty = 1 And _ $Bookmark10Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() EndIf EndIf EndIfThis block of code, and several more similar looking sections, are very lengthy -- using many, many ElseIfs. I've been trying to think of a way to compact it, but it simply isn't coming to me. If there's a way to make it a bit more streamlined, then I'm all ears. Any help on this is appreciated. Edited April 11, 2008 by SixWingedFreak
junkew Posted April 11, 2008 Posted April 11, 2008 (edited) If its only readability make a short helper function For example func bookCheck($BookValue, $BookMarkEmpty) If $Bookmark = $Bookvalue And $BookmarkEmpty = 1 Then Debug("Logging off (bookmark " & $BookValue & " is empty).") Terminate() endif endfunc Code then becomes something like bookCheck("1", $BookMark1Empty) bookCheck("2", $BookMark2Empty) bookCheck("3", $BookMark3Empty) bookCheck("4", $BookMark4Empty) bookCheck("5", $BookMark5Empty) bookCheck("6", $BookMark6Empty) Edited April 11, 2008 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
nitron Posted April 11, 2008 Posted April 11, 2008 expandcollapse popupIf $LogOffExpendedBookmarks = 1 Then Debug("Checking bookmark status.") If $Bookmark = "1" And $Bookmark1Empty = 1 Then Debug("Logging off (bookmark 1 is empty).") Terminate() ElseIf $Bookmark = "2" And $Bookmark2Empty = 1 Then Debug("Logging off (bookmark 2 is empty).") Terminate() ElseIf $Bookmark = "3" And $Bookmark3Empty = 1 Then Debug("Logging off (bookmark 3 is empty).") Terminate() ElseIf $Bookmark = "4" And $Bookmark4Empty = 1 Then Debug("Logging off (bookmark 4 is empty).") Terminate() ElseIf $Bookmark = "5" And $Bookmark5Empty = 1 Then Debug("Logging off (bookmark 5 is empty).") Terminate() ElseIf $Bookmark = "6" And $Bookmark6Empty = 1 Then Debug("Logging off (bookmark 6 is empty).") Terminate() ElseIf $Bookmark = "7" And $Bookmark7Empty = 1 Then Debug("Logging off (bookmark 7 is empty).") Terminate() ElseIf $Bookmark = "8" And $Bookmark8Empty = 1 Then Debug("Logging off (bookmark 8 is empty).") Terminate() ElseIf $Bookmark = "9" And $Bookmark9Empty = 1 Then Debug("Logging off (bookmark 9 is empty).") Terminate() ElseIf $Bookmark = "10" And $Bookmark10Empty = 1 Then Debug("Logging off (bookmark 10 is empty).") Terminate() ElseIf $Bookmark = "Random" Then If $BookmarkAmount = 1 And _ $Bookmark1Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 2 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 3 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 4 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 5 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 6 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 7 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 8 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 And _ $Bookmark8Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 9 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 And _ $Bookmark8Empty = 1 And _ $Bookmark9Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() ElseIf $BookmarkAmount = 10 And _ $Bookmark1Empty = 1 And _ $Bookmark2Empty = 1 And _ $Bookmark3Empty = 1 And _ $Bookmark4Empty = 1 And _ $Bookmark5Empty = 1 And _ $Bookmark6Empty = 1 And _ $Bookmark7Empty = 1 And _ $Bookmark8Empty = 1 And _ $Bookmark9Empty = 1 And _ $Bookmark10Empty = 1 Then Debug("Logging off (all bookmarks are empty).") Terminate() EndIf EndIf EndIf This block of code, and several more similar looking sections, are very lengthy -- using many, many ElseIfs. I've been trying to think of a way to compact it, but it simply isn't coming to me. If there's a way to make it a bit more streamlined, then I'm all ears. Any help on this is appreciated. Hy, maybe im getting this wrong but how about simpy create an AddValue $Count=$Bookmark1Empty to $Bookmark9Empty like $Count=$Bookmark1Empty+$Bookmark2Empty+ etc if $Count=$BookmarkAmount then Debug("Logging off (all bookmarks are empty).") else what ever..
smashly Posted April 11, 2008 Posted April 11, 2008 (edited) Hi, not sure if this is what you mean by shortning the code block. But in this example I set all the values and do a ConsoleWrite, read the scite console after you run the code. ;-- Dummy values as no real values supplied $LogOffExpendedBookmarks = 1 $Bookmark = 1 $BookmarkAmount = 1 For $i = 1 To 10 Assign("Bookmark" & $i & "Empty", "1", 2); Evil Assign a variable fill the variable Next ;--- Loop through the values If $LogOffExpendedBookmarks = 1 Then For $i = 1 To 11; Loop throught the $Bookmark"X"Empty variable using the evil Eval ..lol If $Bookmark = $i And Eval("Bookmark" & $i & "Empty") = 1 Then ConsoleWrite(" Logging off (bookmark " & $i & " is empty)." & @LF) If $i <= 10 Then $Bookmark += 1 If $Bookmark = 11 Then $Bookmark = "Random"; Just so you can see the random loop ConsoleWrite("|---------------------------------------------------------|" & @LF) EndIf ElseIf $Bookmark = "Random" Then For $j = 1 To 10 If $BookmarkAmount = $j Then For $h = 1 To $j If Eval("Bookmark" & $h & "Empty") = 1 Then _ ConsoleWrite(" BookmarkAmount " & $j & "-" & $h & @LF) If $h = $j Then _ ConsoleWrite(" BookmarkAmount " & $j & ": Logging off (all bookmarks are empty)." & @LF) Next ConsoleWrite("|---------------------------------------------------------|" & @LF) EndIf $BookmarkAmount += 1; so you can see that the $Bookmark"X"Empty is being checked Next EndIf Next EndIfHope it helps, but I've probably missed the whole point of what your trying to do.. Cheers Edited April 11, 2008 by smashly
SixWingedFreak Posted April 11, 2008 Author Posted April 11, 2008 Thanks guys, I'm gonna try out some of those suggestions.
Swift Posted April 11, 2008 Posted April 11, 2008 Maybe if it's a little shorter, you may want to use: Switch $Bookmark Case 1 ... Case 2 ... EndSwitch Etc.
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