Checking The value is Greater Than Zero

Hi,

          I have a text box inm my form. I need to check the value in the textBox is Greater than zero in Server Side. So  i tried to do like

Dim txt as Double=TryCast(TxtBox.Text,Double)

if Not(txt isNothing) then

method()

endif 

 

But im Getting error on the

Dim txt as Double=TryCast(TxtBox.Text,Double) error is trycast operand must be reference type,but double is a value type.  pla help me


Thanks,
0
arunpulikkan
4/22/2008 7:12:37 AM
asp.net.visual-basic.net 3721 articles. 0 followers. Follow

2 Replies
695 Views

Similar Articles

[PageSpeed] 58
Get it on Google Play
Get it on Apple App Store

TryCast only works for reference types (i.e. objects). Since double is a value type, you cannot use TryCast for this purpose.

Instead, you should do Double.TryParse(TxtBox.Text, txt) where txt is your Double variable

TryParse returns True if the conversion succeeds, False otherwise. The result of the conversion is stored in the second parameter.


If this post was useful to you, please mark it as answer. Thank you!
0
johram
4/22/2008 7:56:27 AM

Hi,
Why are you casting it?
It may have string value also that's why you are using tryCast...

Otherwise you can simply check like this..

if Convert.ToDouble(textbox.text) > 0

End if


Virendra (MCTS)

My SiteBlog
0
virendra1983
4/22/2008 7:58:24 AM
Reply: