Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Loosing values when working on different functions and modules..

Hello,

I have a userform, and buttons on it...

I have a module, called lnCalculate

And functions..

ln1Calculate
ln2Calculate
...


When i press first button it makes;

a = 6

total = a+b+c+d+e

and second;

b= 7

total=a+b+c+d+e

so in this second step, I want to get a value, 13

But.. I got 7. What i guess is, after finishing first function, all data is
cleared

a,b,c,d,e are identified as double in the forms module...

I do not want to loose the values for a, b, c, d, e.. I want them to save
their values even they are used in different functions or different modules.

I just want them to clear their values only when i want (e.g a=0, b=0.. )

So how must define them so they will not loose their values?

thanks in advance,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Loosing values when working on different functions and modules..

One way is to dec;lare the variables globally (i.e., outside of the
functions).

Option Explicit

Dim a As Double, b As Double, c As Double, d As Double, e As Double

Function ln1Calculate()
a = 6
ln1Calculate = a + b + c + d + e
Debug.Print ln1Calculate 'yields 6
End Function

Function ln2Calculate()
b = 7
ln2Calculate = a + b + c + d + e
Debug.Print ln2Calculate 'yields 13
End Function
__________________________________________________ ___________________
"SupperDuck" wrote in message
...
Hello,

I have a userform, and buttons on it...

I have a module, called lnCalculate

And functions..

ln1Calculate
ln2Calculate
..


When i press first button it makes;

a = 6

total = a+b+c+d+e

and second;

b= 7

total=a+b+c+d+e

so in this second step, I want to get a value, 13

But.. I got 7. What i guess is, after finishing first function, all data
is
cleared

a,b,c,d,e are identified as double in the forms module...

I do not want to loose the values for a, b, c, d, e.. I want them to save
their values even they are used in different functions or different
modules.

I just want them to clear their values only when i want (e.g a=0, b=0.. )

So how must define them so they will not loose their values?

thanks in advance,




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Loosing values when working on different functions and modules

Hello...

Not working...

I am using this variables in different modules. Different functions in
different modules...

I do not know why not working :(


"Vasant Nanavati" wrote:

One way is to dec;lare the variables globally (i.e., outside of the
functions).

Option Explicit

Dim a As Double, b As Double, c As Double, d As Double, e As Double

Function ln1Calculate()
a = 6
ln1Calculate = a + b + c + d + e
Debug.Print ln1Calculate 'yields 6
End Function

Function ln2Calculate()
b = 7
ln2Calculate = a + b + c + d + e
Debug.Print ln2Calculate 'yields 13
End Function
__________________________________________________ ___________________
"SupperDuck" wrote in message
...
Hello,

I have a userform, and buttons on it...

I have a module, called lnCalculate

And functions..

ln1Calculate
ln2Calculate
..


When i press first button it makes;

a = 6

total = a+b+c+d+e

and second;

b= 7

total=a+b+c+d+e

so in this second step, I want to get a value, 13

But.. I got 7. What i guess is, after finishing first function, all data
is
cleared

a,b,c,d,e are identified as double in the forms module...

I do not want to loose the values for a, b, c, d, e.. I want them to save
their values even they are used in different functions or different
modules.

I just want them to clear their values only when i want (e.g a=0, b=0.. )

So how must define them so they will not loose their values?

thanks in advance,





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Loosing values when working on different functions and modules

What is the purpose of using different modules?
__________________________________________________ ______________________

"SupperDuck" wrote in message
...
Hello...

Not working...

I am using this variables in different modules. Different functions in
different modules...

I do not know why not working :(


"Vasant Nanavati" wrote:

One way is to dec;lare the variables globally (i.e., outside of the
functions).

Option Explicit

Dim a As Double, b As Double, c As Double, d As Double, e As Double

Function ln1Calculate()
a = 6
ln1Calculate = a + b + c + d + e
Debug.Print ln1Calculate 'yields 6
End Function

Function ln2Calculate()
b = 7
ln2Calculate = a + b + c + d + e
Debug.Print ln2Calculate 'yields 13
End Function
__________________________________________________ ___________________
"SupperDuck" wrote in message
...
Hello,

I have a userform, and buttons on it...

I have a module, called lnCalculate

And functions..

ln1Calculate
ln2Calculate
..


When i press first button it makes;

a = 6

total = a+b+c+d+e

and second;

b= 7

total=a+b+c+d+e

so in this second step, I want to get a value, 13

But.. I got 7. What i guess is, after finishing first function, all
data
is
cleared

a,b,c,d,e are identified as double in the forms module...

I do not want to loose the values for a, b, c, d, e.. I want them to
save
their values even they are used in different functions or different
modules.

I just want them to clear their values only when i want (e.g a=0,
b=0.. )

So how must define them so they will not loose their values?

thanks in advance,







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
Cells loosing there functions JG Excel Worksheet Functions 5 December 24th 06 04:00 PM
Remove Modules not working Noemi Excel Programming 3 November 1st 06 07:21 AM
Calling functions in different modules CR[_4_] Excel Programming 2 April 11th 05 04:08 PM
Indirect( ) function loosing values when spreadsheets are closed Word4Dummies Excel Worksheet Functions 2 February 13th 05 12:41 PM
VBA & XL2K: Working with objects/class modules Mike Mertes Excel Programming 0 November 1st 04 02:55 PM


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