To convert a numeric string into a corresponding numerical value in VB, the function that should be used is "Val()"; the syntax format of this function is "Val(S,V,Code)", meaning : Convert the string S to the corresponding numeric type and assign it to V. If there are non-numeric characters in the string, then "V:=0", Code can return the position of the non-numeric characters.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
To convert a numeric string into a corresponding numerical value in VB, the function that should be used is "Val()".
Val function can convert character data composed of digital symbols (including positive and negative signs, decimal points) into corresponding numerical data.
Use format usage:
Val(S,V,Code)
Convert the string S into the same numerical type as V and assign it to V. If there are non-digits in the string, then V:=0, Code uses Returns the position of a non-numeric character.
Note:
If non-numeric characters appear in the string, only the part before the non-numeric characters will be converted; if the first character of the string is not a numeric symbol, the value zero will be returned. , but leading spaces are ignored.
Example:
text1.text = "10"
text2.text = "11"
text3.text = text1.text text2.text
Logically, we should get 10 11 (the result is 21), but it returns 1011. This is because the operation is character operation.
text1.text = "10"
text2.text = "11"
text3.text = val(text1.text) val(text2.text)
The returned value is 21.
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of To convert a numeric string into the corresponding numerical value in VB, what function should be used?. For more information, please follow other related articles on the PHP Chinese website!