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

When you have public modules and have declared variables why is it when we
have End in the code (due to information is missing and needs to be added),
why do the variables lose their data

ie
If I have dbcountry = 1 when the program comes to the word End, the
dbcountry = 0.

I dont understand why this happens as I have Public dbcountry as double in a
standard module so I can use over multiple modules.

Any answers would be very much appreciated.
thanks
Noemi
  #2   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default Question Only

Make sure you are declaring your variables outside of any procedures
I've tested the following code. First run test1. It sets the variable test
as one then displays it in a message box. Then run test 2. It still
displays 1 in the message box because test is still holding its value.

I usually create a mode called "Declarations" for all my public variables
and do not write any other code there.

Public test As Integer

Sub test1()
test = 1
MsgBox test
End Sub

Sub test2()
MsgBox test
End Sub
--
JNW


"Noemi" wrote:

When you have public modules and have declared variables why is it when we
have End in the code (due to information is missing and needs to be added),
why do the variables lose their data

ie
If I have dbcountry = 1 when the program comes to the word End, the
dbcountry = 0.

I dont understand why this happens as I have Public dbcountry as double in a
standard module so I can use over multiple modules.

Any answers would be very much appreciated.
thanks
Noemi

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Question Only

Hi JNW

If you put the word End before the End Sub for test1 then it doesn't work.

I have all my varibale in a seperate module with nothing else included.

Any other ideas.

Thanks
Noemi

"JNW" wrote:

Make sure you are declaring your variables outside of any procedures
I've tested the following code. First run test1. It sets the variable test
as one then displays it in a message box. Then run test 2. It still
displays 1 in the message box because test is still holding its value.

I usually create a mode called "Declarations" for all my public variables
and do not write any other code there.

Public test As Integer

Sub test1()
test = 1
MsgBox test
End Sub

Sub test2()
MsgBox test
End Sub
--
JNW


"Noemi" wrote:

When you have public modules and have declared variables why is it when we
have End in the code (due to information is missing and needs to be added),
why do the variables lose their data

ie
If I have dbcountry = 1 when the program comes to the word End, the
dbcountry = 0.

I dont understand why this happens as I have Public dbcountry as double in a
standard module so I can use over multiple modules.

Any answers would be very much appreciated.
thanks
Noemi

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Question Only

Noemi,
Did you check the Help ?
<From Help
Terminates execution immediately. Never required by itself but may be placed
anywhere in a procedure to end code execution, close files opened with the
Open statement and to clear variables.
</From Help
It is by design.

As help says, it is never required, so if it causes problem, do not use it.
Can't say I have ever used it.
If Msgbox ("Exit the routine, without End")=vbYes then Exit Sub

NickHK

"Noemi" wrote in message
...
Hi JNW

If you put the word End before the End Sub for test1 then it doesn't work.

I have all my varibale in a seperate module with nothing else included.

Any other ideas.

Thanks
Noemi

"JNW" wrote:

Make sure you are declaring your variables outside of any procedures
I've tested the following code. First run test1. It sets the variable

test
as one then displays it in a message box. Then run test 2. It still
displays 1 in the message box because test is still holding its value.

I usually create a mode called "Declarations" for all my public

variables
and do not write any other code there.

Public test As Integer

Sub test1()
test = 1
MsgBox test
End Sub

Sub test2()
MsgBox test
End Sub
--
JNW


"Noemi" wrote:

When you have public modules and have declared variables why is it

when we
have End in the code (due to information is missing and needs to be

added),
why do the variables lose their data

ie
If I have dbcountry = 1 when the program comes to the word End, the
dbcountry = 0.

I dont understand why this happens as I have Public dbcountry as

double in a
standard module so I can use over multiple modules.

Any answers would be very much appreciated.
thanks
Noemi



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Question Only

Noemi,
Also, read the rest of the help entry, as using 'End" is probably not a good
idea.

NickHK

"Noemi" wrote in message
...
Hi JNW

If you put the word End before the End Sub for test1 then it doesn't work.

I have all my varibale in a seperate module with nothing else included.

Any other ideas.

Thanks
Noemi

"JNW" wrote:

Make sure you are declaring your variables outside of any procedures
I've tested the following code. First run test1. It sets the variable

test
as one then displays it in a message box. Then run test 2. It still
displays 1 in the message box because test is still holding its value.

I usually create a mode called "Declarations" for all my public

variables
and do not write any other code there.

Public test As Integer

Sub test1()
test = 1
MsgBox test
End Sub

Sub test2()
MsgBox test
End Sub
--
JNW


"Noemi" wrote:

When you have public modules and have declared variables why is it

when we
have End in the code (due to information is missing and needs to be

added),
why do the variables lose their data

ie
If I have dbcountry = 1 when the program comes to the word End, the
dbcountry = 0.

I dont understand why this happens as I have Public dbcountry as

double in a
standard module so I can use over multiple modules.

Any answers would be very much appreciated.
thanks
Noemi



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
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


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