In VB, you may want to convert the data to the numeric type, which can be an integer, a single precision, a double precision, or a floating point number, however, this function returns only the numbers contained in the string. If the first character is a letter or a non-numeric character, the function range is 0.
The help of VB6.0 is as follows:
Returns the number contained in the string, which is a proper type of value.
Syntax
Val (String)
NecessaryStringThe parameter can be any valid string expression.
Description
ValFunction that stops reading strings from the first character that cannot be recognized as a number. Symbols and characters that are considered to be part of the value, such as the US circle number and comma, cannot be recognized. However, functions can recognize carry-in symbols.&O
(Octal) and&H
(Hexadecimal ). Blank spaces, tabs, and line breaks are removed from parameters.
The following return value is 1615198:
Val(" 1615 198th Street N.E.")
In the following code,ValReturns the decimal value-1 for the hexadecimal value.
Val("&HFFFF")
Note: ValThe function will only (.) As an available decimal separator. When different decimal point separators are used, such as in international applicationsCDblTo convert a string to a number.
Val function example
This example usesValThe function returns the value contained in the string.
Dim MyValueMyValue = Val("2457")
'
Return 2457
.MyValue = Val(" 2 45 7")
'
Return 2457
.MyValue = Val("24 and 57")
'
Return 24
.
If you want to use functions in VB in C #, add a reference to Microsoft. VisualBasic. dll and import the namespace.
Using Microsoft. VisualBasic; then use the static Val function in the Conversion class. You can also use a fully qualified name to introduce it, for example
Microsoft. VisualBasic. Conversion. Val ("123abc"); the returned result is 123.
Question: If you want to use functions in other languages, but you do not want to construct them yourself in the language, you can import the DLL of other languages and then reference the functions in it.