The conversion of the string "" to type 'Double' is not valid
Solved
kikou93
Posted messages
438
Status
Membre
-
kikou93 Posted messages 438 Status Membre -
kikou93 Posted messages 438 Status Membre -
Hello,
it's been a while since I asked questions (I was very busy with my studies)
I’m using Visual Basic Express 2010
let me explain my problem and I hope someone can help me
I have, for example, the following condition:
If TextBox1.Text > 0 Then
.....
End if
but it displays the following error:
The conversion of the string "" to type 'Double' is not valid
I tried with:
If CInt(TextBox.Text) > 0
If Val(TextBox.Text) > 0
it works, no error is displayed
but the problem is that if textBox1.text = 0.009 the value that is taken into account is 0 and not 0.009
normally the condition is checked
I also tried with:
If CDbl(TextBox.Text) > 0
but the same error is displayed (The conversion of the string "" to type 'Double' is not valid)
please help me and thank you in advance for your help
--
How it works is cool!
1000 Thanks friends
it's been a while since I asked questions (I was very busy with my studies)
I’m using Visual Basic Express 2010
let me explain my problem and I hope someone can help me
I have, for example, the following condition:
If TextBox1.Text > 0 Then
.....
End if
but it displays the following error:
The conversion of the string "" to type 'Double' is not valid
I tried with:
If CInt(TextBox.Text) > 0
If Val(TextBox.Text) > 0
it works, no error is displayed
but the problem is that if textBox1.text = 0.009 the value that is taken into account is 0 and not 0.009
normally the condition is checked
I also tried with:
If CDbl(TextBox.Text) > 0
but the same error is displayed (The conversion of the string "" to type 'Double' is not valid)
please help me and thank you in advance for your help
--
How it works is cool!
1000 Thanks friends
3 réponses
And in addition to NHenry's advice (hello), do not use accents or any letter modifiers in variable or function names.
If you have to open your project on an English computer, it will bug everywhere.
I showed you the way, not the solution perfectly tailored to your case.
You could write a function that you would call for each TextBox, you could also create an extension method.
But if you apply exactly this code, "0.009" would not be accepted
There would be this
Which would allow accepting "0,009" or "0.009", but a large number with American thousand separators "1,000,000.001" would not work.
At some point, you will have to lock the input format using validation for example
--
When I was little, the Dead Sea was just sick.
George Burns
If you have to open your project on an English computer, it will bug everywhere.
I don't know if this method works but it doesn't make my job easier because the condition I have contains a lot of textBoxes
I showed you the way, not the solution perfectly tailored to your case.
You could write a function that you would call for each TextBox, you could also create an extension method.
But if you apply exactly this code, "0.009" would not be accepted
There would be this
Dim texte as String = "0,009" Dim toto As Double = Convert.ToDouble(texte.Replace(",","."), CultureInfo.GetCultureInfo("fr-FR")) Which would allow accepting "0,009" or "0.009", but a large number with American thousand separators "1,000,000.001" would not work.
At some point, you will have to lock the input format using validation for example
--
When I was little, the Dead Sea was just sick.
George Burns
Well, does "0.009" work or not?
With .NET, there is double.Parse which allows for accepting different cultures than the system's for decimals.
--
I mainly work in VB6 and VB.NET, with a bit of C#, but moderation often brings me to other languages.
In VB.NET, remember to enable "Option Explicit" and "Option Strict."
With .NET, there is double.Parse which allows for accepting different cultures than the system's for decimals.
--
I mainly work in VB6 and VB.NET, with a bit of C#, but moderation often brings me to other languages.
In VB.NET, remember to enable "Option Explicit" and "Option Strict."
Dim toto As Double = Convert.ToDouble("0.009", CultureInfo.GetCultureInfo("en-US"))I configured the textBox as follows:
Dim desNuméro() As Char = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not desNuméro.Contains(e.KeyChar) And Not Asc(e.KeyChar) = 8 Then
e.Handled = True
End If
If e.KeyChar = "."c Or e.KeyChar = ","c Then
e.Handled = True
If Not (TextBox1.Text.Contains(",")) Then TextBox1.AppendText(",")
End If
End Sub
so that the textBox only accepts numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and the comma
so the decimal symbol is the comma and not the point
even if I press the point key, in the textBox it is the comma that appears.
Dim toto As Double = Convert.ToDouble("0.009", CultureInfo.GetCultureInfo("en-US"))I don't know if this method works, but it doesn't make my job easier because the condition I have involves a lot of textBox:
If textBox1.text >0 and textBox2.text>0 and textBox3.text>0 .... and textBox30.text>0 then
.........
End if
Also, remove the automatic import of the namespace "Microsoft.VisualBasic".
I decided to apply Whismeril's method
thank you for taking the time for me, thank you very much