Incorrect VBA custom function parameter type

Source: Internet
Author: User

Iamlaosong

1. Question proposal

When a problem is found in programming, the system always prompts a compilation error. The byref parameter type does not match,

But there is no problem with Parameter definition. Why?

2. Problem Environment

Assume that the function is defined as follows:

Function get_kind (ADDR as string) as integer
......

End Function

Call process:

Sub check_address ()
Dim ADDR, new_addr (10000) as string

......
ADDR = new_addr (I)

......
Kk = get_kind (ADDR)
......
End sub

3. Cause

The type after ADDR value assignment is incorrect. Although the values are strings, array variables are different from individual variables, and the compilation system reports an error.

It is easy to solve the problem by finding the cause:

Method 1: forced conversion, using CSTR (ADDR)

Method 2: Change the variable and assign the value myaddr = ADDR before callingKk = get_kind (myaddr)

4. Problem Expansion

Other types of arrays have the same problem. Isn't this a bug?


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.