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

VulpesRank #55 · 29.2K reputationPosted Oct 10, 2011, 11:39 PM EDT
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
Mamta MRank #268 · 9.4K reputationPosted Oct 10, 2011, 10:43 PM EDT
Instead, you should write:
if (Convert.ToDouble(strEncrypt) > 0)
Rams39 reputationPosted Oct 10, 2011, 11:05 PM EDT
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."Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 11, 2011, 12:05 AM EDT
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".
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 11, 2011, 12:22 AM EDT
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
Rams39 reputationPosted Oct 12, 2011, 12:59 AM EDT
Mamta MRank #268 · 9.4K reputationPosted Oct 12, 2011, 1:08 AM EDT
Rams39 reputationPosted Oct 12, 2011, 2:10 AM EDT