I have an spreadsheet type application I am creating, but I ran into some problems with polymorphism. When all of the expressions need to be calculated, I compile it in CodeDom so I can evaluate the expressions. The whole spreadsheet is actually an object with rows and cells, so I pass that into the compiler, run it in my program, and have it calculate the results. Then I display those results in the spreadsheet.
---- The problem is this -----
If I have the expression "R1C1 + 5" in a cell, in code it is actually "Code.Row[1].Cells[1].getResult() + 5". The problem is, R1C1 can either be a cell containing a string, or a cell containing a double. So if R1C1 contains a number, I want getResult() to return a double. If it isn't a number, I want it to return a string (in this scenario it would result in a compile error, so assume R1C1 contains a number.)
Is there anyway that I can store the result in the Cell object and return either a double or a string at runtime depending on what type the result is? I've tried using the primitive type 'object,' but I end up losing precision and the calculations are wrong. Any solution to this problem would be greatly appreciated. Thanks.
CodeMonkey775 0 Newbie Poster
Recommended Answers
Jump to PostSo what have you tried? We only provide help if you've come up with something...
Jump to PostYou can't really return more than one value from a single method type, even if you do overloading.
But, what you could do is break up your logic some, or use an object that contains a String, a Double, and a Result Code. Have the code return this Result …
All 5 Replies
zandiago 115 Nearly a Posting Maven Featured Poster
CodeMonkey775 0 Newbie Poster
zandiago 115 Nearly a Posting Maven Featured Poster
CodeMonkey775 0 Newbie Poster
alc6379 120 Cookie... That's it Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.