Jump to content
Sign in to follow this  
kor

help with condensing a statement

Recommended Posts

kor

Switch $sHail
                        Case "StaffAdd"
                            For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                $aInput[1][0] = $aClean[$i][1]
                                $aInput[2][0] = $aClean[$i][2]
                                $aInput[3][0] = $aClean[$i][3]
                                $aInput[4][0] = $aClean[$i][4]
                                $aInput[5][0] = $aClean[$i][5]
                                $aInput[6][0] = $aClean[$i][6]
                                $aInput[7][0] = $aClean[$i][7]
                                $iBarCount = 0
                                _Broker()
                            Next
                        Case "StudentAdd"
                            For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                $aInput[1][0] = $aClean[$i][1]
                                $aInput[2][0] = $aClean[$i][2]
                                $aInput[3][0] = $aClean[$i][3]
                                $aInput[4][0] = $aClean[$i][4]
                                $iBarCount = 0
                                _Broker()
                            Next
                        Case "StaffDelete", "StudentDelete"
                            For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                $iBarCount = 0
                                _Broker()
                            Next
                        Case "StaffMove", "StudentMove"
                            For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                $aInput[1][0] = $aClean[$i][1]
                                $iBarCount = 0
                                _Broker()
                            Next
                    EndSwitch

I'm wonering if there is a way to consense this statement so I can just put IF THEN's for the $aInputs into a single statement.

Something like this.

For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                If $sHail <> "StaffAdd" Then $aInput[0][0] = $aClean[$i][0]
                                $aInput[1][0] = $aClean[$i][1]
                                $aInput[2][0] = $aClean[$i][2]
                                $aInput[3][0] = $aClean[$i][3]
                                $aInput[4][0] = $aClean[$i][4]
                                $aInput[5][0] = $aClean[$i][5]
                                $aInput[6][0] = $aClean[$i][6]
                                $aInput[7][0] = $aClean[$i][7]
                                $iBarCount = 0
                                _Broker()
                            Next

Share this post


Link to post
Share on other sites
water

Something like this?

Switch $sHail
                        Case "StaffAdd", "StudentAdd"
                            For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                $aInput[1][0] = $aClean[$i][1]
                                $aInput[2][0] = $aClean[$i][2]
                                $aInput[3][0] = $aClean[$i][3]
                                $aInput[4][0] = $aClean[$i][4]
                                If $sHail = "StaffAdd" Then
                                    $aInput[5][0] = $aClean[$i][5]
                                    $aInput[6][0] = $aClean[$i][6]
                                    $aInput[7][0] = $aClean[$i][7]
                                EndIf
                                $iBarCount = 0
                                _Broker()
                            Next
                        Case "StaffDelete", "StudentDelete"
                            For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                $iBarCount = 0
                                _Broker()
                            Next
                        Case "StaffMove", "StudentMove"
                            For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                $aInput[1][0] = $aClean[$i][1]
                                $iBarCount = 0
                                _Broker()
                            Next
                    EndSwitch

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kor

Sort of. The goal would be to condense everything down into a single For Next loop so I dont have to have a Switch statement and multiple For Next loops for the different scenarios.

Share this post


Link to post
Share on other sites
water

Why do you want to get rid of the Switch statement? If it works ...


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kor

I'm always trying to teach myself ways to make code more efficient. Why do in 30 lines what you can do in 10.

Maybe something like this.

Not sure if you can have Case statements where the Switch is repeated.

For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
                                $aInput[0][0] = $aClean[$i][0]
                                Switch $sHail
                                    Case "StaffAdd", "StudentAdd", "StaffMove", "StudentMove", "StaffAdd"
                                        $aInput[1][0] = $aClean[$i][1]
                                        ContinueCase
                                    Case "StaffAdd", "StudentAdd"
                                        $aInput[2][0] = $aClean[$i][2]
                                        $aInput[3][0] = $aClean[$i][3]
                                        $aInput[4][0] = $aClean[$i][4]
                                        ContinueCase
                                    Case "StaffAdd"
                                        $aInput[5][0] = $aClean[$i][5]
                                        $aInput[6][0] = $aClean[$i][6]
                                        $aInput[7][0] = $aClean[$i][7]
                                EndSwitch
                                $iBarCount = 0
                                _Broker()
                            Next

Share this post


Link to post
Share on other sites
water

Not sure if you can have Case statements where the Switch is repeated.

You can't. AutoIt processes one Case and then leaves the Switch construct.

If you use ContinueCase the statements following the next Case are executed but the condition isn't evaluated.

There was a discussing this topic a few days ago.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kor

Any way to get the behavior I am looking for then? The code in my last post is a good example of what I am trying to accomplish.

Share this post


Link to post
Share on other sites
water

For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
    $aInput[0][0] = $aClean[$i][0]
    If $sHail = "StaffAdd" Or $sHail = "StudentAdd" Or $sHail = "StaffMove" Or $sHail = "StudentMove" Or $sHail = "StaffAdd" Then
        $aInput[1][0] = $aClean[$i][1]
    EndIf
    If $sHail = "StaffAdd" Or $sHail = "StudentAdd" Then
        $aInput[2][0] = $aClean[$i][2]
        $aInput[3][0] = $aClean[$i][3]
        $aInput[4][0] = $aClean[$i][4]
    EndIf
    If $sHail = "StaffAdd" Then
        $aInput[5][0] = $aClean[$i][5]
        $aInput[6][0] = $aClean[$i][6]
        $aInput[7][0] = $aClean[$i][7]
    EndIf
    $iBarCount = 0
    _Broker()
Next


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
qsek

Switch $sHail
    Case "StaffAdd"
        _Broker($iStartRow, $aClean, $aInput, 7, $i)
    Case "StudentAdd"
        _Broker($iStartRow, $aClean, $aInput, 4, $i)
    Case "StaffDelete", "StudentDelete"
        _Broker($iStartRow, $aClean, $aInput, 0, $i)
    Case "StaffMove", "StudentMove"
        _Broker($iStartRow, $aClean, $aInput, 1, $i)
EndSwitch

Func _Broker($_iStartRow, ByRef $_aClean, ByRef $_aInput, $iNum, $iOrg)
    For $i = $_iStartRow To UBound($_aClean) - 1 ; convert cleanarray columns into variable array equivalents
        For $i = 0 To $iNum
            $_aInput[$i][0] = $aClean[$iOrg][$i]
        Next
    Next
    $iBarCount = 0

    ; rest of _Broker Func

EndFunc   ;==>_Broker

Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
Spiff59

I always go straight to using tables to reduce code size.

Does this behave similar to your examples?

Global $aArray[6][2] = [["StaffAdd",7],["StudentAdd",4],["StaffMove",1],["StudentMove",1],["StaffDelete",0],["StudentDelete",0]]
    
For $i = $iStartRow To UBound($aClean) - 1 ; convert cleanarray columns into variable array equivalents
    For $j = 0 to 5
        If $sHail = $aArray[$j][0] Then
            For $k = 0 to $aArray[$j][1]
                $aInput[$k][0] = $aClean[$i][$k]
            Next
            $iBarCount = 0 ; ought to be first line of _Broker() ?
            _Broker()
            ExitLoop
        EndIf
    Next
Next

Share this post


Link to post
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
Sign in to follow this  

×