Type checking problems

RobinReborn

New member
Joined
Feb 20, 2008
Messages
2
Programming Experience
3-5
Hi, I downloaded http://www.gemboxsoftware.com/GBSpreadsheet.htm (it let's me read and write excel in VB.NET without actually loading excel itself, I don't think that that program is relevant in solving the problem but it might be, the namespace info can be found http://www.gemboxsoftware.com/help/index.html) and am trying to write a program that verifies a spreadsheet has the correct structure.

I must check formatting data from one spreadsheet and compare it to raw data from another. I have to see if a field is unique, and if so, I must check the column corresponding to the field for duplicates. This would be a relatively simple problem if it weren't for the fact that different cells in excel contain different datatypes and comparisons between different datatypes causes an error in VB.NET, I've tried to write something that makes sure I am dealing with the right datatype (string, because I go through the sheet until I find "" indicating there is no more data), but it doesn't work I get the error:
Conversion from string "" to type 'Double' is not valid

Here is the relevant code (efCheck is a workbook):

If efCheck.Worksheets("DataRequest").Cells(rowsCheckedforUniqueInstance, rowscheckedforUniqueColumns - 1).Value.GetType() Is "".GetType() Then


While (efCheck.Worksheets("DataRequest").Cells(rowsCheckedforUniqueInstance, rowscheckedforUniqueColumns - 1).Value <> "")

(that is the line that causes the error).

I don't see how it is getting by the if statement if it's dealing with a double.

Thanks in advance.
 
While is a loop, you can't validate all loop values by a preceeding If statement that checks one single value.
You could possibly loop While ...Value.ToString <> String.Empty
 
Thanks, but when I do that it says "NullReferenceException was unhandled by user code" when it is looking at an empty cell in the spreadsheet.
 
I see, I was wondering about that, if these cells appeared as null values for their formatted type or actual null references. In that case you should be able to loop While ...Value IsNot Nothing
 
Back
Top