如果发生状况,关于类型数据转换的错误消息 [英] ERROR MESSAGE ABOUT TYPE DATA CONVERSION IN IF CONDITION
问题描述
嗨
如果字符串中有数字双精度值,则要在计算中使用该值,您需要将字符串取为双精度型.为此,您可以(例如)调用一个函数来执行此操作.下面的函数可以用字符串调用 它将以数字而不是字符串的形式返回double值.
私有函数GetDouble(以字符串形式)为Double 昏暗v为双= 0.0 如果Double.TryParse(s,v)然后返回v 回报0.0 结束功能您可以像这样使用它:
'示例字符串 Dim s As String ="12.345" '只是将double值放入变量中 昏暗n作为Double = GetDouble(s) '在样本计算值中使用它 昏暗的myCalculation为Double = 10 * GetDouble(s)
i want to make a neutron activation calculator with VB. in my program, user has to input the name of atom (AL, H, K, Mn, etc) so that the calculator can run. Every atom has its own property, like mass, isotopic abundance, etc. i decide to make my program
run like this, IF user write AL then mass=2.3 isotopic abundance = 0.5 . IF user write H then mass=2.8 isotopic abundance = 0.2. after the value is defined, the program can run. input AL store in variable "atom" with string data type. Variable mass
and isotopic abundance with double data type. when i run my program, it said error in conversion STRING to DOUBLE. i dont know how to fix it. could anyone help me with this problem? thank you very much.
Hi
If you have a numeric double value in a string, then to use the value in a calculation, you need to take the string and change it to a double. To do this, you can (for example) call a function to do this. The function below can be called with the string and it will return the double value as a number rather than a string.
Private Function GetDouble(s As String) As Double Dim v As Double = 0.0 If Double.TryParse(s, v) Then Return v Return 0.0 End FunctionYou can use it like this:
' example string Dim s As String = "12.345" ' just get the double value into a variable Dim n As Double = GetDouble(s) ' use it in a sample calculated value Dim myCalculation As Double = 10 * GetDouble(s)
这篇关于如果发生状况,关于类型数据转换的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!