declarations

J

jimbo_jones

I have some code working between modules and a form, but I don't
understand how its working with the way I declared the variables.

I want a value from a Sub in a module to be passed to a Sub in the
form. What is the proper way to do this?

What is the difference between, Public, Private and Global for
variables? Thanks
 
C

Chip Pearson

The difference between Public and Private (Global is an obsolete
term, use Public instead) is called 'scope' which refers to where
the variables can be accessed. If you declare a variable as
Public, it can be accessed (read from or written to) by any
procedure in any module, or by any procedure in any module in any
project that references the containing project.

If you declare a variable as Private (the default), it can be
accessed only from procedures in that module.

If you declare a Public variable in a form's code module, you
must prefix it with the form's name if you need to use that
variable in any other module. E..g,

[in the userform]
Public MyVar As Integer

[in Module1]
Userform1.MyVar = 123

The same holds for procedures declared in a userform. E.g.

[in the userform]
Public Sub MySub(S As String)
MsgBox S
End Sub

[in Module1]
UserForm1.MySub "abc"




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com










"jimbo_jones"
in message
news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top