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


Is this the right syntax for declaring a variable to be public? This i
what I found in the VB Help File.

Public Statement Example
This example uses the Public statement at the module level (Genera
section) of a standard module to explicitly declare variables a
public; that is, they are available to all procedures in all modules i
all applications unless Option Private Module is in effect.

Public Number As Integer ' Public Integer variable. But executing the following code code gives me the error "Invali

Attribute in Sub or Function" occurring at the "Public mystr..." line.
______________________
Sub mysub1()
Public mystr As String
mystr = "hello world"
End Sub
______________________

Also, I'm guessing mysub1() needs to be executed just once before thos
strings are set in memory?

Thanks,

To

--
ob3ron0
-----------------------------------------------------------------------
ob3ron02's Profile: http://www.excelforum.com/member.php...fo&userid=1545
View this thread: http://www.excelforum.com/showthread.php?threadid=27204

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Declaring Variables Public

You declare the variable at the top of the module (a general module),
outside any procedure

Public mystr As String

Sub mysub1()
mystr = "hello world"
End Sub

You would need to execute some code to give the variable a value.

If the value will not change, you could declare a constant:

Public Const MyConst As String = "ABCD"


Sub Testit()
MsgBox MyConst
End Sub


--
Regards,
Tom Ogilvy

"ob3ron02" wrote in message
...

Is this the right syntax for declaring a variable to be public? This is
what I found in the VB Help File.

Public Statement Example
This example uses the Public statement at the module level (General
section) of a standard module to explicitly declare variables as
public; that is, they are available to all procedures in all modules in
all applications unless Option Private Module is in effect.

Public Number As Integer ' Public Integer variable. But executing the

following code code gives me the error "Invalid
Attribute in Sub or Function" occurring at the "Public mystr..." line.
______________________
Sub mysub1()
Public mystr As String
mystr = "hello world"
End Sub
______________________

Also, I'm guessing mysub1() needs to be executed just once before those
strings are set in memory?

Thanks,

Tom


--
ob3ron02
------------------------------------------------------------------------
ob3ron02's Profile:

http://www.excelforum.com/member.php...o&userid=15450
View this thread: http://www.excelforum.com/showthread...hreadid=272045



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
Declaring variables in Module vs. Public Jeff Excel Discussion (Misc queries) 5 November 19th 07 08:27 PM
declaring a public array JT[_2_] Excel Programming 3 July 27th 04 11:18 PM
Declaring Public Procedure mac Excel Programming 3 December 3rd 03 05:01 PM
Declaring Variables Robert[_16_] Excel Programming 2 November 20th 03 04:16 PM
Declaring Variables chris brunt Excel Programming 2 August 4th 03 02:02 PM


All times are GMT +1. The time now is 09:25 AM.

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

About Us

"It's about Microsoft Excel"