Hi All,
iam passing a textbox value(the value is 10:1:1) into a string and when iam running the application iam getting the following error "coversion from string "10:1:1" to double type is invalid". kindly find the code below and help me on the same: (also the textbox values should be greater than 0 always)
Dim strEncrypt As String = txtData.Text
If strEncrypt > 0 Then// iam getting the error here txtEncryptedData.Text = Encrypt(strEncrypt)
Else MessageBox.Show(
"Enter the Value greater then 0:")End If
Thanks,
Rams
Loading
VulpesPosted Oct 11, 2011, 3:39 AM
You could split the string first and then convert each element to a double:
Dim elements As String() = strEncrypt.Split(":"c)
Dim d As Double = Double.Parse(elements(0))
MessageBox.Show(d.ToString()) ' 10
RamsPosted Oct 12, 2011, 6:10 AM
Mamta MPosted Oct 12, 2011, 5:08 AM
RamsPosted Oct 12, 2011, 4:59 AM
Prabhu RajaPosted Oct 11, 2011, 4:22 AM
i agree with vulpes, its good one. Also try this one.
Dim elements As String() = strEncrypt.Split(":"c);
Dim firstnumber As Double;
// Try to use TryParse(), you handle Conversion Errors effectively. Your Application will not be disturbed by these kind of errors.
bool isConverted = Double.TryParse(elements(0).ToString(), out firstnumber) ;
if ( isConverted == true)
// Value Converted Successfully
Else
// Value Conversion failed.
MessageBox.Show(d.ToString()); ' 10
Javeed M ShaikhPosted Oct 11, 2011, 4:05 AM
If you want to check that the textbox value does not start with "0" than use the following:
if (!TextBox1.Text.Trim().StartsWith("0"))
{
// do your stuff here
}
Also I am not sure if you can convert value "10:1:1" to double.
Please do not forget to mark "Accepted Answer".
RamsPosted Oct 11, 2011, 3:05 AM
I tried with
If(
i want to check that the textbox value does not start with 0
Convert.ToDouble(strEncrypt) > 0) but iam getting the error as "Input string was not in a correct format."Mamta MPosted Oct 11, 2011, 2:43 AM
Instead, you should write:
if (Convert.ToDouble(strEncrypt) > 0)