Home >Common Problem >To convert a numeric string into the corresponding numerical value in VB, what function should be used?

To convert a numeric string into the corresponding numerical value in VB, what function should be used?

青灯夜游
青灯夜游Original
2021-01-30 16:36:2712386browse

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.

To convert a numeric string into the corresponding numerical value in VB, what function should be used?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is rmcNext article:what is rmc