Jump to content

help with condensing a statement


kor
 Share

Recommended Posts

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

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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