in vb, you can use text which is in textbox instead of numerical expressions. I mean, if I write 50 in textbox1 and also I can write like that code:
Dim result As Double = TextBox1.Text + 0.4
as you see, I didnt convert any type but it works in vb.net
But I want to learn what are disadvantages of this using?
(I am just talking about arithmetic operations)
In VB.NET you will only get away with this if you have OPTION STRICT turned off – otherwise, you’ll generate an error.
In programmming, you should always try to be as precise as possible with your data types. So you could write your line of code as:
Alternatively, you could do some error trapping:
There are a lot of other things you can use, include TryParse. You can even use VBA functions like CDbl too.
If you rely on what is called implicit type conversion, VB.NET will attempt to convert the data type for you. The disadvantage of this approach is that it makes for lazy programming. On this occasion you want VB.NET to be fault-tolerant, but how about when you don’t? If you allow it to correct your errors, you’ll eventually get the situation where you generate bugs because your code isn’t enforcing the correct data type.
Right – that’s the party line over. Personally, I quite like the way VBA casts data types behind the scenes for me!