What value type is Global in Visual Basic?

If I have something defined like this:

Global ErrorStatus&

And I have know what data type this is. I have heard that the compiler sets the data type based on how it is used. Well, suppose I have this problem where I have to know what the default type it is because I am sending it to a C++ DLL. What type should I expect?

Recommended Answers

All 3 Replies

In the defination above, you will have a variable (ErrorStatus&), which is global to the entire project. So any form, module, control, or anything within your project will have access to the variable. It should also be noted, that the variable in your example, is of type LONG, and the reason it's a LONG is because of the &. If, however, you left off the &, and just left the variable as ErrorStatus, then the type would be defined as a variant by default... as far as I know, no other language recognizes the variant data type, but I'm not 100% on that.
Variants are crappy types of variables, and should only be used in rare instances, however, your example above is Not a variant, but a LONG....

I don't use Global. I put all my public declarations in a Module:

Public ErrorStatus as Long

Global ErrorStatus&

Use the varType function: it returns the variable type.

You can use it from the Immediate Window

That will return a numerical value. Then you consult your MSDN documentation to see what type corresponds with that numerical value.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.