From VB. NET to VB6.0, be careful about using the pair number functions of iif and log (minor knowledge of concatenation)

Source: Internet
Author: User
Ladies and gentlemen, I have found a small problem today. I would like to share it with you here. I hope it will be helpful for your future development and at least take a detour. It is not an esoteric thing, please read the content in a relaxed mood:
In VB.net, we can use system. math. log function, but it is different from VB6.0. net support for polymorphism, and log (a) is based on E by default and log (A, newbase). The latter supports changing the base number, such as system. math. log () is the base-2 logarithm of 8, but the problem is that sometimes we may process a = 0 when we are unknown to the variable, in VB.net, the solution of log (0) = "negative infinity" is very simple. If you want log (0) = 0 (of course, aside from the mathematical meaning, I mainly use it to explain the problem. In fact, sometimes log (0) = 0 is very useful here. For example, when the chart difference is too large, the small numbers shown in the figure are not obvious. you can use the number of logarithm to solve the problem, but some numbers will be 0 ......) Use an IIF function to process IIF (expression, true, false). For example:
V = IIF (A =, system. Math. Log ()
However, when we return to VB6.0 to process a previous project today, we encounter an error message when v = Log (a) is used to handle invalid function processing. The cause is that a = 0, if there is any difficulty, I can use v = IIF (A =, log (a) to let a = 0 return 0 to me, in this way, you can avoid errors and go on a business trip. The error prompt is the same as the original one. In the past, the Microsoft team did not handle exceptions at 6.0, in addition, you must count parameters in the order of function processing before passing in function processing. Therefore, if you think you are smart, you still cannot avoid processing logs (a = 0 ), therefore, in VB6.0, we had to honestly use if expresion then ...... : Else ...... : The expression of at least five sentences of the end if statement is actually similar and occupies space. Therefore, when we return to VB6.0, we should be careful. This also shows that the Microsoft team is careful, like these (IIF and log) in. net2003 has already been changed. It also shows that IIF is not necessarily effective for processing all simple conditions and the importance of handling exceptions
Finally, to change the base number in VB6.0, log (y)/log (x) can be used to process the base y logarithm with X, because log does not support polymorphism.
Proof:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.