Significance of an ampersand in VB6 function name?

2020-02-27 12:44发布

I just got a bunch of legacy VB6 (!) code dumped on me and I keep seeing functions declared with an ampersand at the end of the name, for example, Private Declare Function ShellExecute& . . ..

I've been unable to find an answer to the significance of this, nor have I been able to detect any pattern in use or signature of the functions that have been named thusly.

Anyone know if those trailing ampersands mean anything to the compiler, or at least if there's some convention that I'm missing? So far, I'm writing it off as a strange programmer, but I'd like to know for sure if there's any meaning behind it.

标签: vb6 sigils
2条回答
成全新的幸福
2楼-- · 2020-02-27 13:07

It means that the function returns a Long (i.e. 32-bit integer) value.

It is equivalent to

Declare Function ShellExecute(...) As Long

The full list of suffixes is as follows:

Integer %
Long    &
Single  !
Double  #
Currency @
String  $
查看更多
混吃等死
3楼-- · 2020-02-27 13:16

As Philip Sheard has said it is an indentifier type for a Long. They are still present in .Net, see this MSDN link and this VB6 article

From the second article:

The rules for forming a valid VB variable name are as follows:

(1) The first character must be a letter A through Z (uppercase or lowercase letters may be used). Succeeding characters can be letters, digits, or the underscore (_) character (no spaces or other characters allowed).

(2) The final character can be a "type-declaration character". Only some of the variable types can use them, as shown below:

Data Type  Type Declaration Character  

String         $  
Integer        %  
Long           &  
Single         !  
Double         #  
Currency       @    

Use of type-declaration characters in VB is not encouraged; the modern style is to use the "As" clause in a data declaration statement.

查看更多
登录 后发表回答