Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'Expected End If' in excel function
#1
Hello,

Ive got an excel function that highlights a row in an excel file. I have previously tested this test, and it worked as planned, but I have since then added cases to a conditional branch.

I have even commented out the section that i thought was having trouble, and replaced it with a Select Case structure, but i still get the error:

Expected 'End If' Line 189, which is the last line of this code block.. the line that ends the function.

The function itself is called within an if..else structure. The code for this structure is posted below the function code.

Any ideas on why this may be occurring?

Thanks,

Incite1321

--------------

Code:
' where sourcefilepath is the LocalDataTable for the test, the targetfilepath is the target excel log file ' n is the current row to be modified -- same for both the excel file at sourcefilepath, and the log excel file at targetfilepath, since they are copies of each other Function logerrorinexcel(sourcefilepath, targetfilepath, error_type, n) 'define the excel variables Dim objExcel Dim objWorkBook Dim objSheet ' now lets open up the excel sheet so that we can modify it set objExcel = CreateObject("Excel.Application") objExcel.visible = true set objWorkBook = objExcel.Workbooks.Open(targetfilepath) set objSheet = objExcel.ActiveWorkbook.Sheets("Create_Multiple_Divisions") objWorkBook.Worksheets("Create_Multiple_Divisions").Activate 'determine the type of error ' If error_type = "Duplicate" Then ' 'now lets highlight the target row +1 ... since there is a header row in the file... in our new copy ' objExcel.Rows(n+1).Interior.ColorIndex = 19 ' Else if (error_type = "NoParent") Then ' 'error is of type NoParent ' objExcel.Rows(n+1).Interior.ColorIndex = 24 ' Else if (error_type = "InvalidParent") Then ' 'error is of type InvalidParent ' objExcel.Rows(n+1).Interior.ColorIndex = 35 ' Else if (error_type = "InvalidExt") Then ' 'error is of type InvalidExt ' objExcel.Rows(n+1).Interior.ColorIndex = 37 ' Else ' 'error is of type other, so we paint it differently ' objExcel.Rows(n+1).Interior.ColorIndex = 20 ' End If Select Case error_type Case "Duplicate" 'now lets highlight the target row +1 ... since there is a header row in the file... in our new copy objExcel.Rows(n+1).Interior.ColorIndex = 19 Case "NoParent" 'error is of type NoParent objExcel.Rows(n+1).Interior.ColorIndex = 24 Case "InvalidParent" 'error is of type InvalidParent objExcel.Rows(n+1).Interior.ColorIndex = 35 Case "InvalidExt" 'error is of type InvalidExt objExcel.Rows(n+1).Interior.ColorIndex = 37 Case Else 'error is of type other, so we paint it differently objExcel.Rows(n+1).Interior.ColorIndex = 20 End Select 'save data and close objExcel.DisplayAlerts = False objWorkBook.SaveAs targetfilepath objWorkBook.Close objExcel.DisplayAlerts = True objExcel.Quit End Function

--------------

Code:
If InStr(0, (Browser("Login_2").Page("Admin Users").Object.getElementsByName("body").innerHtml), "Unable to add new contact.") <> Null Then ' an error occurred, log the type If Browser("Login_2").Page("Admin Users").WebElement("Division with this name").Exist Then 'we have a duplicate. err_type = "Duplicate" errstr = "Duplicate at Datatable row #: " & i call logerrorintxt(srctest, errstr) call logerrorinexcel(srcfilepath, tarfilepath, err_type, i) Else If Browser("Admin Users_2").Page("Admin Users").WebElement("At least one parent is").Exist Then 'a parent was not selected or selected correctly err_type = "NoParent" errstr = "Parent not selected correctly at Datatable row #: " & i call logerrorintxt(srctest, errstr) call logerrorinexcel(srcfilepath, tarfilepath, err_type, i) Else If Browser("Admin Users_2").Page("Admin Users").WebElement("Selected parent has to").Exist Then 'the parent that was selected is invalid err_type = "InvalidParent" errstr = "Parent that was selected is invalid at Datatable row #: " & i call logerrorintxt(srctest, errstr) call logerrorinexcel(srcfilepath, tarfilepath, err_type, i) Else If Browser("Admin Users_2").Page("Admin Users").WebElement("Extension must be numeric").Exist Then 'an extension was not formatted correctly err_type = "InvalidExt" errstr = "Extension entered is invalid at Datatable row #: " & i call logerrorintxt(srctest, errstr) call logerrorinexcel(srcfilepath, tarfilepath, err_type, i) Else 'data in spreadsheet not formatted correctly err_type = "Other" errstr = "Data not formatted correctly at Datatable row #: " & i call logerrorintxt(srctest, errstr) call logerrorinexcel(srcfilepath, tarfilepath, err_type, i) End If End If
Reply
#2
Hi,
Try replacing 'ELSE IF' with ELSEIF
This will solve the issue.

Thanks,
Saket

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Expected End statement error Lavanya N 2 5,834 07-27-2015, 01:52 PM
Last Post: Lavanya N
  How to check expected cookies are present or not priyanka.agarwal 0 2,326 07-02-2015, 12:43 PM
Last Post: priyanka.agarwal
  Calling a function in a Test Script from a function library anupam4j 3 6,993 06-26-2015, 12:31 AM
Last Post: babu123
  Validate Numeric value is displaying expected format kalaivanan123 1 3,916 09-23-2013, 08:45 PM
Last Post: ravi.gajul
  closing browser at end bistritapcv 3 7,081 04-12-2013, 07:21 AM
Last Post: basanth27

Forum Jump:


Users browsing this thread: 1 Guest(s)