Current location - Training Enrollment Network - Mathematics courses - What does the val function in vb mean?
What does the val function in vb mean?
The Val function is used to convert a data line variable into a digital long integer variable.

such as

text 1.text = " 10 "

text2.text = " 1 1 "

Text 3. Text = text 1. Text+text 2. Text

Logically, you should get10+1(the result is 2 1), but what does it return? 10 1 1 was returned. This is because the operation is a character operation, so it will not work.

So what should we do?

text 1.text = " 10 "

text2.text = " 1 1 "

text 3 . text = val(text 1 . text)+val(text 2 . text)

This will return 2 1, because we are not calculating "11"+"12", but11+. The former is equivalent to "11"&; " 12"

If it is a string or a space, it will return 0, so you can use this to filter characters and only enter numbers.