Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default declarations


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


--
jimbo_jones
------------------------------------------------------------------------
jimbo_jones's Profile: http://www.excelforum.com/member.php...o&userid=27244
View this thread: http://www.excelforum.com/showthread...hreadid=470257

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default declarations

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"
wrote
in message
...

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


--
jimbo_jones
------------------------------------------------------------------------
jimbo_jones's Profile:
http://www.excelforum.com/member.php...o&userid=27244
View this thread:
http://www.excelforum.com/showthread...hreadid=470257



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default declarations


Thanks Chip! this will cear up the voodoo magic which is happening wit
my code

--
jimbo_jone
-----------------------------------------------------------------------
jimbo_jones's Profile: http://www.excelforum.com/member.php...fo&userid=2724
View this thread: http://www.excelforum.com/showthread.php?threadid=47025

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declarations Procedure and Duplicate Declarations Neal Zimm Excel Programming 3 May 31st 05 01:01 AM
Understanding declarations Greg[_16_] Excel Programming 1 January 26th 05 09:35 PM
Help with Array Declarations Mark \(InWales\)[_19_] Excel Programming 4 December 20th 04 06:39 AM
Capitalization in Declarations Phil Hageman[_3_] Excel Programming 16 December 24th 03 11:01 PM
Strange variable declarations Steven Revell Excel Programming 1 August 19th 03 02:19 PM


All times are GMT +1. The time now is 05:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"