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

Hi,

What is the procedure to initliaze a variable as soon as the a macro
is invoked. The variable and its value, thus initialized, needs to be
accessible to other macros and procedures being executed in sequence
thereafter.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Variable Initialization

See 'Public Statement' in VBA help file.

" wrote:

Hi,

What is the procedure to initliaze a variable as soon as the a macro
is invoked. The variable and its value, thus initialized, needs to be
accessible to other macros and procedures being executed in sequence
thereafter.

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Variable Initialization

There are 2 ways to make variable accessable to other procedure. One is to
declare the variable globally. While this seems like a good way to go you can
end up with a project that is very difficult to maintain. A better way to
make a variable accessabel to another procedure is to pass it to that
procedure.

1 - Global Example
dim str as string

sub MainStuff()
str = "this"
call OtherStuff
end sub

sub OtherStuff
str = str & " and that"
msgbox str
end sub

2 - Passing Example


sub MainStuff()
dim str as string
str = "this"
call OtherStuff(str)
end sub

sub OtherStuff(byval str as string)
str = str & " and that"
msgbox str
end sub

--
HTH...

Jim Thomlinson


" wrote:

Hi,

What is the procedure to initliaze a variable as soon as the a macro
is invoked. The variable and its value, thus initialized, needs to be
accessible to other macros and procedures being executed in sequence
thereafter.

Thanks.

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
UserForm Initialization Patrick C. Simonds Excel Programming 2 February 21st 08 08:48 PM
Conditional Initialization adewole Excel Programming 0 July 31st 07 04:14 PM
Userform Initialization Patrick Simonds Excel Programming 2 May 22nd 04 10:17 PM
List box initialization Tom Ogilvy Excel Programming 0 July 15th 03 05:41 PM
List box initialization Daniel Thompson Excel Programming 0 July 15th 03 05:17 PM


All times are GMT +1. The time now is 01:05 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"