Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I understand the reason for declaring variables, but get fed up with declaring them for each Sub in each module. Can I declare my vaiables in 'This Workbook' using public. Can I also 'publicly' declare what the vaiable refers to so that if I do the following Public TodaysDate As String that I could use TodaysDate = Worksheets("Dates").range("UpdateToday") TodaysDate = Format(TodaysDate, "dd-mmm-yy") in any module/sub. Unfortunately I have to work with dates that are strings and others that are dates in various formats. Thanks for any help / advice Richard |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
You can declare variables as public at the top of any code module & they will be available to all modules. If you want TodaysDate to be a date or a string, then declare it as a Variant. You might want to pause and rethink your strategy here though. When it comes to managing a lot of code in several modules & you have some debugging to do on a code rewrite you will dearly, dearly wish you hadn't gone down this road... More than that, I would put as much commentary as I could next to each variable as it is declared to tell me exactly what it is for. regards Paul On Jul 3, 10:30*am, Richard wrote: Hi, I understand the reason for declaring variables, but get fed up with declaring them for each Sub in each module. * Can I declare my vaiables in 'This Workbook' using public. Can I also 'publicly' declare what the vaiable refers to so that if I do the following Public TodaysDate As String that I could use TodaysDate = Worksheets("Dates").range("UpdateToday") TodaysDate = Format(TodaysDate, "dd-mmm-yy") in any module/sub. Unfortunately I have to work with dates that are strings and others that are dates in various formats. Thanks for any help / advice Richard |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() wrote in message ... You might want to pause and rethink your strategy here though. When it comes to managing a lot of code in several modules & you have some debugging to do on a code rewrite you will dearly, dearly wish you hadn't gone down this road... What is the rationale for this argument? I typically have dozens of modules in my appplications. That is all part of modular/OO techniques. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Bob,
Think he is talking about declaring all ones variables as public in one location - as suggested by the OP - not using multiple modules. I would amend Paul's statement about declaring variables public in any module to qualify any module to be any general/standard module (since the OP specifically mentioned the Thisworkbook module as I recall) -- Regards, Tom Ogilvy "Bob Phillips" wrote: wrote in message ... You might want to pause and rethink your strategy here though. When it comes to managing a lot of code in several modules & you have some debugging to do on a code rewrite you will dearly, dearly wish you hadn't gone down this road... What is the rationale for this argument? I typically have dozens of modules in my appplications. That is all part of modular/OO techniques. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I think the poster wants to declare a variable once and then use that name in several modules, within several subs, and for it to mean several different things. It was the variable scoping I suggested he rethink - not the modularity. regards Paul On Jul 3, 12:56*pm, "Bob Phillips" wrote: wrote in message ... You might want to pause and rethink your strategy here though. When it comes to managing a lot of code in several modules & you have some debugging to do on a code rewrite you will dearly, dearly wish you hadn't gone down this road... What is the rationale for this argument? I typically have dozens of modules in my appplications. That is all part of modular/OO techniques. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
public variables | Excel Discussion (Misc queries) | |||
Public variables | Excel Discussion (Misc queries) | |||
Public Variables | Excel Programming | |||
Public Variables | Excel Programming | |||
Public Variables | Excel Programming |