I have the following problem, I have two modules, that means two macros, in
my application and there are some subroutines which are common and I was
trying to have them in only one module and to call them by module1.sub_name.
These subs change the value of a global variable which has purposely the same
name in both modules but I noticed that when I call them by that way the
value of the global variables do not change.

Does anyone know if I am doing something wrong or why is this happening? It
should be another way except of copying the subroutines in both modules,
right?

Re: global variables - shared subroutines by Jonathan

Jonathan
Thu Jul 28 04:56:33 CDT 2005

Hi Mirka,

Declare the global variable in only one place. Declare it before the first
routine in a module, and use the Public keyword. Make sure that there are no
duplicate declarations anywhere.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

"Mirka" <Mirka@discussions.microsoft.com> wrote in message
news:DA2F7676-9618-493F-85B2-4754FA56D1C4@microsoft.com...
>I have the following problem, I have two modules, that means two macros, in
> my application and there are some subroutines which are common and I was
> trying to have them in only one module and to call them by
> module1.sub_name.
> These subs change the value of a global variable which has purposely the
> same
> name in both modules but I noticed that when I call them by that way the
> value of the global variables do not change.
>
> Does anyone know if I am doing something wrong or why is this happening?
> It
> should be another way except of copying the subroutines in both modules,
> right?


Re: global variables - shared subroutines by Mirka

Mirka
Thu Jul 28 08:25:04 CDT 2005

Thank you Jonathan for your reply.

I followed your steps -I haven't thought about the public declaration of the
variable- but once again the value of my global variable does not change when
I call the sub from the other module.

"Jonathan West" wrote:

> Hi Mirka,
>
> Declare the global variable in only one place. Declare it before the first
> routine in a module, and use the Public keyword. Make sure that there are no
> duplicate declarations anywhere.
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>
> "Mirka" <Mirka@discussions.microsoft.com> wrote in message
> news:DA2F7676-9618-493F-85B2-4754FA56D1C4@microsoft.com...
> >I have the following problem, I have two modules, that means two macros, in
> > my application and there are some subroutines which are common and I was
> > trying to have them in only one module and to call them by
> > module1.sub_name.
> > These subs change the value of a global variable which has purposely the
> > same
> > name in both modules but I noticed that when I call them by that way the
> > value of the global variables do not change.
> >
> > Does anyone know if I am doing something wrong or why is this happening?
> > It
> > should be another way except of copying the subroutines in both modules,
> > right?
>
>

Re: global variables - shared subroutines by Jonathan

Jonathan
Thu Jul 28 08:33:08 CDT 2005

Can you show me the code you are using, both to declare the variable and to
change it? Indicate the exact name and type of module where both the
variable declaration and calling code are located.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

"Mirka" <Mirka@discussions.microsoft.com> wrote in message
news:2BBA80CC-B1AE-43F4-B18E-D623D6631642@microsoft.com...
> Thank you Jonathan for your reply.
>
> I followed your steps -I haven't thought about the public declaration of
> the
> variable- but once again the value of my global variable does not change
> when
> I call the sub from the other module.
>
> "Jonathan West" wrote:
>
>> Hi Mirka,
>>
>> Declare the global variable in only one place. Declare it before the
>> first
>> routine in a module, and use the Public keyword. Make sure that there are
>> no
>> duplicate declarations anywhere.
>>
>> --
>> Regards
>> Jonathan West - Word MVP
>> www.intelligentdocuments.co.uk
>> Please reply to the newsgroup
>> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>>
>> "Mirka" <Mirka@discussions.microsoft.com> wrote in message
>> news:DA2F7676-9618-493F-85B2-4754FA56D1C4@microsoft.com...
>> >I have the following problem, I have two modules, that means two macros,
>> >in
>> > my application and there are some subroutines which are common and I
>> > was
>> > trying to have them in only one module and to call them by
>> > module1.sub_name.
>> > These subs change the value of a global variable which has purposely
>> > the
>> > same
>> > name in both modules but I noticed that when I call them by that way
>> > the
>> > value of the global variables do not change.
>> >
>> > Does anyone know if I am doing something wrong or why is this
>> > happening?
>> > It
>> > should be another way except of copying the subroutines in both
>> > modules,
>> > right?
>>
>>


Re: global variables - shared subroutines by Mirka

Mirka
Fri Jul 29 01:40:03 CDT 2005

I have two modules in the folder 'modules' of my project, module1 and module2.

I declare my variables 'version', 'inMaster' and 'inDetails' at the
beginning of module1 before my first function by this way: public version as
integer, public inMaster as boolean and public inDetails as boolean. Then in
module1 again I have the following sub:

Public Sub Determine_Location_Version(ByVal xNode As MSXML2.IXMLDOMNode)

' We get out from "Master" but not out of "Body"
If inMaster = True And xNode.ParentNode.nodeName = "Body" Then
inMaster = False
End If

' We get in "Master"
If xNode.nodeName = "Master" Then
inMaster = True
' Check which xml version we have
If xNode.HasChildNodes Then
For i = 0 To xNode.ChildNodes(0).ChildNodes.Length - 1
If xNode.ChildNodes(0).ChildNodes(i).nodeName = caption Then
version = 2
End If
Next
End If
End If

' We get out from "Details" but not out of "Body"
If inDetails = True And xNode.ParentNode.nodeName = "Body" Then
inDetails = False
End If

' We get in "Details"
If xNode.nodeName = "Details" Then
inDetails = True
End If

End Sub


In module2 I do not declare these 3 variables once again as you told me and
I call the sub somewhere in my code by: module1.Determine_Location_Version
xNode.

"Jonathan West" wrote:

> Can you show me the code you are using, both to declare the variable and to
> change it? Indicate the exact name and type of module where both the
> variable declaration and calling code are located.
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>
> "Mirka" <Mirka@discussions.microsoft.com> wrote in message
> news:2BBA80CC-B1AE-43F4-B18E-D623D6631642@microsoft.com...
> > Thank you Jonathan for your reply.
> >
> > I followed your steps -I haven't thought about the public declaration of
> > the
> > variable- but once again the value of my global variable does not change
> > when
> > I call the sub from the other module.
> >
> > "Jonathan West" wrote:
> >
> >> Hi Mirka,
> >>
> >> Declare the global variable in only one place. Declare it before the
> >> first
> >> routine in a module, and use the Public keyword. Make sure that there are
> >> no
> >> duplicate declarations anywhere.
> >>
> >> --
> >> Regards
> >> Jonathan West - Word MVP
> >> www.intelligentdocuments.co.uk
> >> Please reply to the newsgroup
> >> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
> >>
> >> "Mirka" <Mirka@discussions.microsoft.com> wrote in message
> >> news:DA2F7676-9618-493F-85B2-4754FA56D1C4@microsoft.com...
> >> >I have the following problem, I have two modules, that means two macros,
> >> >in
> >> > my application and there are some subroutines which are common and I
> >> > was
> >> > trying to have them in only one module and to call them by
> >> > module1.sub_name.
> >> > These subs change the value of a global variable which has purposely
> >> > the
> >> > same
> >> > name in both modules but I noticed that when I call them by that way
> >> > the
> >> > value of the global variables do not change.
> >> >
> >> > Does anyone know if I am doing something wrong or why is this
> >> > happening?
> >> > It
> >> > should be another way except of copying the subroutines in both
> >> > modules,
> >> > right?
> >>
> >>
>
>