Jump to content

Error: EndIf with no matching If statement (but it's there...)


aleph01
 Share

Recommended Posts

I get an error when I don't think I should...

For $i = $LineCount to 1 Step -1
    If _Excel_RangeRead ($oWorkbook, Default, "C" & $i) <> "login" Then
        _Excel_RangeDelete ($oWorkbook.ActiveSheet, $i & ":" & $i)
    Else
        $aTemp = StringSplit(_Excel_RangeRead($oWorkbook, Default, "E" & $i), ",")
        Select
            Case StringInStr($aTemp[$a], "00:19:92:07:50:80")
                $sfCount = $sfCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:06:bd:20")
                $sfCount = $sfCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:0a:4b:60")
                $sfCount = $sfCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:35:59:40")
                $prCount = $prCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:35:14:80")
                $prCount = $prCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:35:97:40")
                $prCount = $prCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:35:a6:80")
                $prCount = $prCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:00:ac:60")
                $cuCount = $cuCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:0b:a0:40")
                $cuCount = $cuCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:0b:ab:40")
                $cuCount = $cuCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:02:8f:60")
                $hpCount = $hpCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:02:8c:60")
                $hpCount = $hpCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:02:8f:c0")
                $hpCount = $hpCount + 1
            Case StringInStr($aTemp[$a], "00:19:92:4b:ea:a0")
                $hpCount = $hpCount + 1
    EndIf
Next

Error: "EndIf" statement with no matching "If" statement.  I know 14 Case Select statements seems like a lot, but I figured it would be faster than 14 If statements in a row.  I would like to test to see if this script is going to get me a count of wireless APs at different sites by MAC addy from log files, but I get this error.  If 14 If statements would be just as fast, that's cool, but I don't understand why I get an If/EndIf error here.

Thanks for any response.

_aleph_

 

btw, is there a reason for the rainbow colors in the code entered here? 

Edit:  Sorry, after posting, the "rainbow colors" changed into color-coded code.  Cool.

Edited by aleph01

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

That's a good idea, Bert, but first I need to get the script running.  I've fixed the case select.  Now the script runs and deletes the non login entries in the .csv file, and it seems to be taking the time to look through the cases, but I have a MsgBox at the end to tell me how many are at each branch, and it tells me 0 for each branch.  I think that my lines like  Case StringInStr($aTemp[$a], "00:19:92:4b:ea:a0") aren't addressing the correct cell or something.  At any rate, I'm getting no matches for any of the cases, although there clearly should be a match for each remaining line in the file.

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

It may be elsewhere in your code, but are you sure you're valuing the $a variable properly in your $aTemp array?  If so, maybe try doing an _ArrayDisplay on that $aTemp array before it runs through your Select statements so you can see the exact data that's about to be evaluated.

Link to comment
Share on other sites

MuffinMan (a Zappa fan? - I'm right there with you :)), you were absolutely right. An _ArrayDisplay revealed that the info I was interested in, MAC addy, was in the 6th element of the splitString array.  $a needed to be 6.  Now my branch totals are populating.

I'm a step closer, but I have found that the .cvs, after processing, has more login entries than my total of the branches.  Some rows apparently don't have the mac addy in the 6th element, or something else is not working just right.

What a learning experience! (Somewhat frustrating, as well, but this is a monthly report I'm trying to automate - I have time <said like a true immortal.>)  Maybe I mistyped when entering a MAC addy or something. 

I think my script is doing everything I scripted it to do.  I just need to find what is causing the discrepancy.  If I fail, I'll be back to pick brains again.

Thanks to all who have contributed ideas and solutions.

This forum is a great resource.  I have, in the past, posted things that were misunderstood, but I have never been disappointed with the quality of help found herein.

My sincere gratitude to the moderators.

Thanks again,

_aleph_

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

I've found that I had a couple of MAC addy wrong - that explains why I had 181 login lines in my sample log, but the script was not finding them all.  That's been corrected.  In fact, my script works flawlessly now. 

Bert, if you're monitoring this string, I took a look at using an array for all of the MAC addy, but I don't see how that would prevent me from having as many Cases, it's just that they would be addressing different elements of my array, rather than the MAC Addys directly.  Would you care to explain how I can use an array in this script  to my advantage?  Also, is there a way to set a number of variables to = 0 without writing one on each line?  I got an error when trying to do so - something about one per line...

    As you can see from the working code below, I have a number of variables that I set to = 0

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         twk with thanks to JLogan3o13 and others on the AutoIt forums
 Date:           9/7/2016
 Script Function:
    Automate manipulation of wireless logs
     in order to get report statistics.

#ce ----------------------------------------------------------------------------

#include <File.au3>
#include <Excel.au3>

$LineCount = 0
$cuCount = 0
$sfCount = 0
$hpCount = 0
$prCount = 0
$sf5080 = 0
$cuac60 = 0
$pr5940 = 0
$pr1480 = 0
$sfbd20 = 0
$sf4b60 = 0
$pra740 = 0
$pra680 = 0
$cua040 = 0
$cua640 = 0
$hp8f60 = 0
$hp8c60 = 0
$hp8fc0 = 0
$hpeaa0 = 0
dim $aTemp

$oExcel = _Excel_Open ()
$sFilePath = "C:\Users\Sal\Desktop\downloadSample.csv"
$oWorkbook = _Excel_BookOpen ( $oExcel, $sFilePath)
$LineCount = _FileCountLines ($sFilePath)
dim $aTemp
$ProcessCount = Round (_FileCountLines ($sFilePath)/425, 0)
MsgBox (1, "", $LineCount & " entries; estimated time to process: " & $ProcessCount & " minutes.")


For $i = $LineCount to 1 Step -1
    If _Excel_RangeRead ($oWorkbook, Default, "C" & $i) <> "login" Then
        _Excel_RangeDelete ($oWorkbook.ActiveSheet, $i & ":" & $i)
    Else
        $aTemp = StringSplit(_Excel_RangeRead($oWorkbook, Default, "E" & $i), ",")
;_ArrayDisplay ($aTemp)
        Select
            Case StringInStr($aTemp[6], "00:19:92:07:50:80")
                $sfCount = $sfCount + 1
                $sf5080 = $sf5080 + 1
            Case StringInStr($aTemp[6], "00:19:92:08:ac:60")
                $cuCount = $cuCount + 1
                $cuac60 = $cuac60 + 1
            Case StringInStr($aTemp[6], "00:19:92:35:59:40")
                $prCount = $prCount + 1
                $pr5940 = $pr5940 + 1
            Case StringInStr($aTemp[6], "00:19:92:35:14:80")
                $prCount = $prCount + 1
                $pr1480 = $pr1480 + 1
            Case StringInStr($aTemp[6], "00:19:92:06:bd:20")
                $sfCount = $sfCount + 1
                $sfbd20 = $sfbd20 + 1
            Case StringInStr($aTemp[6], "00:19:92:0b:a0:40")
                $cuCount = $cuCount + 1
                $cua040 = $cua040 + 1
            Case StringInStr($aTemp[6], "00:19:92:0a:4b:60")
                $sfCount = $sfCount + 1
                $sf4b60 = $sf4b60 + 1
            Case StringInStr($aTemp[6], "00:19:92:35:a7:40")
                $prCount = $prCount + 1
                $pra740 = $pra740 + 1
            Case StringInStr($aTemp[6], "00:19:92:35:a6:80")
                $prCount = $prCount + 1
                $pra680 = $pra680 + 1
            Case StringInStr($aTemp[6], "00:19:92:0b:a6:40")
                $cuCount = $cuCount + 1
                $cua640 = $cua640 + 1
            Case StringInStr($aTemp[6], "00:19:92:02:8f:60")
                $hpCount = $hpCount + 1
                $hp8f60 = $hp8f60 + 1
            Case StringInStr($aTemp[6], "00:19:92:02:8c:60")
                $hpCount = $hpCount + 1
                $hp8c60 = $hp8c60 + 1
            Case StringInStr($aTemp[6], "00:19:92:02:8f:c0")
                $hpCount = $hpCount + 1
                $hp8fc0 = $hp8fc0 + 1
            Case StringInStr($aTemp[6], "00:19:92:4b:ea:a0")
                $hpCount = $hpCount + 1
                $hpeaa0 = $hpeaa0 + 1
        EndSelect
    EndIf
Next

$total = $cuCount + $sfCount + $prCount + $hpCount
$cuPercentage = Round ($cuCount/$total*100, 2)
$sfPercentage = Round ($sfCount/$total*100, 2)
$hpPercentage = Round ($hpCount/$total*100, 2)
$prPercentage = Round ($prCount/$total*100, 2)

MsgBox (1, "Totals", "CU = " & $cuCount & ", SF = " & $sfCount & ", PR = " & $prCount & ", HP = " & $hpCount & ", TOTAL = " &  $total & ".")
MsgBox (1, " Branch Percentages", "CU = " & $cuPercentage & "%" & ", SF = " & $sfPercentage & "%" & ", PR = " & $prPercentage & "%" & ", HP = " & $hpPercentage & "%.")
MsgBox (1, "Counts by MAC Address", _
"sf-50:80 = " & $sf5080 &@LF& _
"cu-ac:60 = " & $cuac60 &@LF& _
"pr-59:40 = " & $pr5940 &@LF& _
"pr-14:80 = " & $pr1480 &@LF& _
"sf-bd:20 = " & $sfbd20 &@LF& _
"cu-a0:40 = " & $cua040 &@LF& _
"sf-4b:60 = " & $sf4b60 &@LF& _
"pr-a7:40 = " & $pra740 &@LF& _
"pr-a6:80 = " & $pra680 &@LF& _
"cu-a6:40 = " & $cua640 &@LF& _
"hp-8f:60 = " & $hp8f60 &@LF& _
"hp-8c:60 = " & $hp8c60 &@LF& _
"hp-8f:c0 = " & $hp8fc0 &@LF& _
"hp-ea:c0 = " & $hpeaa0)

 

Edited by aleph01
more info

Meds.  They're not just for breakfast anymore. :'(

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