Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|