Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a variable in more than one sub procedure
I currently have this is a sub and parts of the sub use the answer.
This sub will run first. Dim answer as integer answer = inputbox(How many sheets?) However i would like to use the answer again in another sub that runs later, without the input box again. Is this possible? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a variable in more than one sub procedure
If the sub is on the same module/sheet/userform then you should just
make a global variable for it: e.g. "Dim glDescriberAnwer as long" at the top of the form. When the other sub(s) wants to use it, just be sure the code is smart enough to know the un-initialized variable (i.e. 0) isn't what the user inputted. If necessary, use a separate (boolean) global variable to tell if the variable has been initialized or not. keri wrote: I currently have this is a sub and parts of the sub use the answer. This sub will run first. Dim answer as integer answer = inputbox(How many sheets?) However i would like to use the answer again in another sub that runs later, without the input box again. Is this possible? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a variable in more than one sub procedure
Sorry i'm new to Excel and my knowledge is tiny.
I'm guessing you mean to declare the variable where it says Option Explicit. Does the gl refer to it being a global variable? How and where would I put the othere variable to show true/false if it has been answered already? And once I had this second variable would I have to refer to it with an If statement, eg currently my second use of answer says; For p = 1 to answer Would it have to be For p = 1 to answer if bla is true? How would I word this? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a variable in more than one sub procedure
Sorry i'm new to Excel and my knowledge is tiny.
I'm guessing you mean to declare the variable where it says Option Explicit. Does the gl refer to it being a global variable? How and where would I put the othere variable to show true/false if it has been answered already? And once I had this second variable would I have to refer to it with an If statement, eg currently my second use of answer says; For p = 1 to answer Would it have to be For p = 1 to answer if bla is true? How would I word this? |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a variable in more than one sub procedure
Sorry i'm new to Excel and my knowledge is tiny.
I'm guessing you mean to declare the variable where it says Option Explicit. Does the gl refer to it being a global variable? How and where would I put the othere variable to show true/false if it has been answered already? And once I had this second variable would I have to refer to it with an If statement, eg currently my second use of answer says; For p = 1 to answer Would it have to be For p = 1 to answer if bla is true? How would I word this? |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a variable in more than one sub procedure
Hi Keri
Yes, declare the variable after Option Explicit and before the first of your Subs. The gl doesn't make it global it is just a convention used by many to show that this is a global variable utilised by many routines. In your case, Answer is the number of pages, and if the question hasn't been asked, then the value will be 0 from the original dim statement so I don't think you need to worry about setting a Boolean as to whether you have answered. Just change your loops to If answer 0 Then For p =1 to answer . rest of your code here |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using a variable in more than one sub procedure
Thanks.
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Procedure name as variable | Excel Programming | |||
Variable procedure call | Excel Programming | |||
Call procedure using variable | Excel Programming | |||
Public/Procedure Variable | Excel Programming | |||
can I call a procedure using a variable | Excel Programming |