PDA

View Full Version : Integer & String



doctortt
04-04-2011, 12:28 PM
I have this cell formated percentage. If I were to enter 10, the cell will give me 10% and if I were to enter .1, the cell will also give me 10%.

I'm writing some codes that need to use this cell. Should I dim this cell as string or integer?

Mathmatically, I know 0.1 is not an integer.

Please shed some lights on this.

Thanks

Bob Phillips
04-04-2011, 12:49 PM
No, you should dim it as Double.

doctortt
04-04-2011, 01:43 PM
No, you should dim it as Double.

Thanks for replying, but would you mind to explain why Double?

Bob Phillips
04-04-2011, 01:46 PM
Because it has a decimal portion and double will handle that, integer will not.

doctortt
04-04-2011, 01:51 PM
Because it has a decimal portion and double will handle that, integer will not.

Thanks a lot. What about String? Can string handle it?

CareerChange
04-04-2011, 03:29 PM
You should cast the variable to the data type that most represents its most used state.

For example, if you're doing mostly numeric operations w this particular variable, then cast it as Double, and if/when the time comes to represent it as a string, use Str() or Format() to do the conversion.

Likewise, if you cast is as String, use CDbl to convert it to a Double.

mikerickson
04-04-2011, 11:22 PM
Cells contain only data types Double, String, Boolean, or Error.

When reading from a cell, I always use Variant data type. I never trust the user to put the right data in the cell.