|
-
Nov 2nd, 2001, 10:27 AM
#1
Thread Starter
Fanatic Member
Declaring API, public?
I have some graphic api declarations in a module, i had to declare them like
VB Code:
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
if i removed the public at the start, the program would not function properly.
Why is this?
-
Nov 2nd, 2001, 10:28 AM
#2
Thread Starter
Fanatic Member
Ooooops
my bad, i realized what was wrong, it wasnt nuthink to do with the declares but some constants.
While im at it then, whats the difference at putting a public infront? ( when its in a module )
-
Nov 2nd, 2001, 10:33 AM
#3
Anything (function, sub, datatype) that is Public in a module can be referenced from any other form or module.
Private means that nobody outside of the module can see it.
-
Nov 2nd, 2001, 10:42 AM
#4
If you don't preface the Declare Function Yada with Public (in a module) or Private (in a form) VB can get confused about what you are talking about.
-
Nov 2nd, 2001, 12:30 PM
#5
PowerPoster
Well
This is generally a rule of thumb I try to use. This way you can call it from wherever you need it it your program...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Nov 2nd, 2001, 07:22 PM
#6
I like tight code. Be judicious in the use of Public anythings. I've seen variables declared as Public, and used on one form, or even worse, in one sub routine/function. A good, general rule of thumb is to, as you are developing your project, declare your variables at the procedure level. Then, if you find yourself needing them in other procedures, move their declaration to the form level.
There are things that need to be exposed to the entire project, and thus need to be placed in a module, and declared Public. However, there aren't that many.
-
Nov 2nd, 2001, 10:52 PM
#7
PowerPoster
Well
There are things that need to be exposed to the entire project, and thus need to be placed in a module, and declared Public. However, there aren't that many.
That many? I use global settings for file, path, connection strings to databases, user name throughout program , along with their level of access, global arrays, alot of stuff...
Maybe I am wrong, but I like to be able to access my info from wherever in the project I might need it...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Nov 2nd, 2001, 11:09 PM
#8
Public variables & especially Public Subs and Functions are necessary.
Without going into my age - suffice it to say that globals are a necessary evil - and I've seen them for LOOONG time.
You can abstract data to the point you make the program hard to understand & maintain, even if it supposedly makes 'tighter code'.
Redundant functions are a REAL NO-NO, hence the need for Public Functions.
In the code I've seen over the years - good production code, about 5% of the variables are global. Formatting functions, I/O functions, and general purpose functions also fall into the public area.
-
Nov 3rd, 2001, 11:32 AM
#9
Originally posted by Hack
If you don't preface the Declare Function Yada with Public (in a module) or Private (in a form) VB can get confused about what you are talking about.
VB won't get confused, rather, the programmer will. If you don't specifically declare a function/sub with a scope modifier, VB will default it to public.
-
Nov 5th, 2001, 08:53 AM
#10
Conquistador
WHy does a Form accept
Declare Function yadayadayada then?
As it doesn't accept Public Declare Function, but will accept Private...
?
Wouldn't the form reject Declare??
i've confused myself
-
Nov 5th, 2001, 03:40 PM
#11
A Form doesn't accept either of the following:
Code:
Declare Function...
Public Declare Function...
But it does accept
Code:
Private Declare Function
-
Nov 6th, 2001, 12:16 AM
#12
Conquistador
Ahh ok.
I thought that it accepted Declare Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|