Jump to content

Some optimization help needed.


Recommended Posts

If $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.

Edited by SixWingedFreak
Link to comment
Share on other sites

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 by junkew
Link to comment
Share on other sites

If $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..

Link to comment
Share on other sites

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
EndIf
Hope it helps, but I've probably missed the whole point of what your trying to do..

Cheers

Edited by smashly
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...