Forum Discussion

DCat1223's avatar
DCat1223
Frequent Contributor
9 years ago

Help with an error message when executing a keyword test.

Good afternoon, and thank you for taking the time to read this.

I am having trouble with a keyword test.

The piece giving me trouble is referencing a value in a spreadsheet in a column called “DCRA Annual Amt”. The data in the spreadsheet are all set up properly as project level variables. 

The part I am struggling with is a basic If…Then statement that basically says:

If ProjectSuite.Variables.EmpData("DCRA Annual Amt") Equals Decline, do this… Else do this.

 

This was not working.

To troubleshoot, I added a Code Snipped, showMessage… just before the If…Then to show me what the value was that is being read from the Excel sheet to be used in the If…Then:

BuiltIn.ShowMessage(ProjectSuite.Variables.EmpData("DCRA Annual Amt"))

 

This is failing, giving me the following error:

An error occurred while executing the code snippet: Could not convert variant of type (Null) into type (String) and I am guessing if the messagebox can’t find the value, then this has something to do with the If…Then failing as well.

 

I have attached screenshots of both the keyword test and the spreadsheet.

 

What is making me crazy is if I change the Code Snipped to look at any of the other fields in my spreadsheet to the left or right of the DCRA Annual Amt field, I receive the expected value returned in the message box. It’s just this column that is causing me trouble.  I have attached a screenshot. 

 

My question is, what could be causing the An error occurred while executing the code snippet: Could not convert variant of type (Null) into type (String) message?

  • The DB provider chooses whether a column is considered as data or text.  Changing the format of the data only changes the  view of the data, not the underlying value. What happens if you write a little test to read the values for a column one at a time and log them?

     

    For more information, check this article Using Excel Files as Data Storages and this Forum article Trouble getting desired excel data

     

  • cunderw's avatar
    cunderw
    Community Hero

    When using excel make sure ALL cells of your column have the same type/format. This is a common error when working with Excel Sheets. Testcomplete does not recogize different data types/formats in the same column.

    • DCat1223's avatar
      DCat1223
      Frequent Contributor

      Thanks for the quick reply.  All cells (including the heading) are formatted as Currency.  Just to be sure, I selected the whole column, changed it to Text, then back to Currency.  I also tried formatting to Text and running it.  Still the same error.  Any other thoughts?   

      • cunderw's avatar
        cunderw
        Community Hero

        You have decline right above the first number, which means you have numbers and text, they should all be text.