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


<<sorry. Shld have posted my message here instead of the
General section

Hi! Friends.

Can someone help:

I wish to preserve the value of a variable (say n) each
time I run the procedure, I have:

Sub count()
Static n as integer

n=n+1

end sub

May I know how I can start with an initial value of n
other than 0. I use CALL sub, but doesnt work.

Many thanks.
..


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Stattic Variable

Check for possible solutions in the .misc group.


In general, it's better to stick to one thread, even if it's in the
wrong group so that answers don't get fragmented. The time to repost
is if you don't get any answers in the original group within a
reasonable time (an hour or twelve, perhaps).


In article ,
"Lee" wrote:

<<sorry. Shld have posted my message here instead of the
General section

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Stattic Variable

Always the same start number?

Tim

Sub dostatic()

Const X_START As Integer = 5
Static x As Integer

If x = 0 Then x = X_START

MsgBox x
x = x + 1
End Sub

"Lee" wrote in message
...

<<sorry. Shld have posted my message here instead of the
General section

Hi! Friends.

Can someone help:

I wish to preserve the value of a variable (say n) each
time I run the procedure, I have:

Sub count()
Static n as integer

n=n+1

end sub

May I know how I can start with an initial value of n
other than 0. I use CALL sub, but doesnt work.

Many thanks.
.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Stattic Variable

Instead of using a static local variable, you could also use a module-level variable and a
separate sub that initializes it to whatever value you want.


On Tue, 2 Sep 2003 21:32:48 -0700, "Lee" wrote:


<<sorry. Shld have posted my message here instead of the
General section

Hi! Friends.

Can someone help:

I wish to preserve the value of a variable (say n) each
time I run the procedure, I have:

Sub count()
Static n as integer

n=n+1

end sub

May I know how I can start with an initial value of n
other than 0. I use CALL sub, but doesnt work.

Many thanks.
.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Stattic Variable

Another option is that if you want the numbers to start with, say, 10, just add 10 to the
reported value.


On Tue, 2 Sep 2003 21:32:48 -0700, "Lee" wrote:


<<sorry. Shld have posted my message here instead of the
General section

Hi! Friends.

Can someone help:

I wish to preserve the value of a variable (say n) each
time I run the procedure, I have:

Sub count()
Static n as integer

n=n+1

end sub

May I know how I can start with an initial value of n
other than 0. I use CALL sub, but doesnt work.

Many 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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
can i link a variable cost code with a variable sum I need help!! Excel Discussion (Misc queries) 0 August 1st 08 11:40 AM
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM


All times are GMT +1. The time now is 11:51 PM.

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"