How declare a public variable that can be edit by forms?VB.Net

  • Thread starter Thread starter MJ
  • Start date Start date
M

MJ

as topic, if i wan to create an array where the content of
the array can be edited by form1 and form2, how i going to
do it?
for example the content of array is {1,2,3}

form2 change the content to {1,2,4}

form1 also can see the changes in the array
where i should declare the array and wat is the format?
and how am i going to call the array in form1 and form2
for modification?
any help is greatly appreciated...thz...
 
Hi MJ,

If it is a fixed array you can do making a shared class as this

Public Class mySample
Private Shared myRealArray As Integer() = {1, 2, 3}
Public Shared Property MyArray() As Integer()
Get
Return myRealArray
End Get
Set(ByVal Value As Integer())
myRealArray = Value
End Set
End Property
End Class

Now you can use everywhere that array by
mySample.myArray(2) = 4

But have a look at arraylist also, because this is not such a nice example,
I did try to answer your question exactly as you was asking. If you want to
redim your array, you have to add a method to your class. (public shared Sub
or function)

I hope this helps,

Cor
 
Hi,

In addition to Cor's comments you need to make a public array in a
module to make available through the project.

Public myArray() As Integer = {1, 2, 3}


Ken
 
Hi Ken,
In addition to Cor's comments you need to make a public array in a
module to make available through the project.


Sorry for trying correctiong you, but I think you did want to say

In addition to Cor's comments you can also make a public array in a
module to make available through the project.

If I dont post this the OP does maybe understand it wrong and does both.

:-)

Cor
 
* "MJ said:
as topic, if i wan to create an array where the content of
the array can be edited by form1 and form2, how i going to
do it?
for example the content of array is {1,2,3}

form2 change the content to {1,2,4}

form1 also can see the changes in the array
where i should declare the array and wat is the format?
and how am i going to call the array in form1 and form2
for modification?
any help is greatly appreciated...thz...

Place the array declaration in a module or a class (declared as
'Shared'), for example:

\\\
Public Module Globals
Private m_MyArray() As Integer

Public Property MyArray() As Integer()
Get
Return m_MyArray
End Get
Set(ByVal Value As Integer())
m_MyArray = Value
End Set
End Property
End Module
///

Access the array with 'Globals.MyArray'.
 
I thought that as well Cor.

Regards - OHM#
Hi Ken,



Sorry for trying correctiong you, but I think you did want to say

In addition to Cor's comments you can also make a public array in a
module to make available through the project.

If I dont post this the OP does maybe understand it wrong and does
both.

:-)

Cor

Regards - OHM# (e-mail address removed)
 
PS:

I prefer your method to create a Class rather than declaring an array in the
Module

Hi Ken,



Sorry for trying correctiong you, but I think you did want to say

In addition to Cor's comments you can also make a public array in a
module to make available through the project.

If I dont post this the OP does maybe understand it wrong and does
both.

:-)

Cor

Regards - OHM# (e-mail address removed)
 
MJ,

You might also want to create an isChanged event in the class to
notify the other form when one changes it.
 
OHM,
I prefer the shared variable in a Class (Cor's example) as well, as its
better "encapsulated". Other developers know that the array is coming from
that class, where as with a Module the array could be coming from any number
of modules.

I normally only use Modules for truly global functions, such as Math
functions. However even then sometimes I will make a class with only Shared
functions.

Jay
 
erm. Thats what I said !

<confused> - OHM#
OHM,
I prefer the shared variable in a Class (Cor's example) as well, as
its better "encapsulated". Other developers know that the array is
coming from that class, where as with a Module the array could be
coming from any number of modules.

I normally only use Modules for truly global functions, such as Math
functions. However even then sometimes I will make a class with only
Shared functions.

Jay


"One Handed Man [ OHM# ]"
PS:

I prefer your method to create a Class rather than declaring an
array in the Module



Regards - OHM# (e-mail address removed)

Regards - OHM# (e-mail address removed)
 
Hi,

Sorry. You are correct.

Ken
--------
Cor said:
Hi Ken,



Sorry for trying correctiong you, but I think you did want to say

In addition to Cor's comments you can also make a public array in a
module to make available through the project.

If I dont post this the OP does maybe understand it wrong and does both.

:-)

Cor
 
OHM,
Yes I was agreeing with you & Cor!

I did not mean to confuse you, it was more re-iterate what you stated, plus
add a caution of using modules in general...

Jay


One Handed Man said:
erm. Thats what I said !

<confused> - OHM#
OHM,
I prefer the shared variable in a Class (Cor's example) as well, as
its better "encapsulated". Other developers know that the array is
coming from that class, where as with a Module the array could be
coming from any number of modules.

I normally only use Modules for truly global functions, such as Math
functions. However even then sometimes I will make a class with only
Shared functions.

Jay


"One Handed Man [ OHM# ]"
PS:

I prefer your method to create a Class rather than declaring an
array in the Module


Cor wrote:
Hi Ken,

In addition to Cor's comments you need to make a public array in a
module to make available through the project.


Sorry for trying correctiong you, but I think you did want to say

In addition to Cor's comments you can also make a public array in a
module to make available through the project.

If I dont post this the OP does maybe understand it wrong and does
both.

:-)

Cor

Regards - OHM# (e-mail address removed)

Regards - OHM# (e-mail address removed)
 
LOL, I'm easily confused today as I have a chest infection. Just ignore me.

Cheers - OHM#
OHM,
Yes I was agreeing with you & Cor!

I did not mean to confuse you, it was more re-iterate what you
stated, plus add a caution of using modules in general...

Jay


"One Handed Man [ OHM# ]"
erm. Thats what I said !

<confused> - OHM#
OHM,
I prefer the shared variable in a Class (Cor's example) as well, as
its better "encapsulated". Other developers know that the array is
coming from that class, where as with a Module the array could be
coming from any number of modules.

I normally only use Modules for truly global functions, such as Math
functions. However even then sometimes I will make a class with only
Shared functions.

Jay


"One Handed Man [ OHM# ]"
PS:

I prefer your method to create a Class rather than declaring an
array in the Module


Cor wrote:
Hi Ken,

In addition to Cor's comments you need to make a public array in
a module to make available through the project.


Sorry for trying correctiong you, but I think you did want to say

In addition to Cor's comments you can also make a public array in
a module to make available through the project.

If I dont post this the OP does maybe understand it wrong and does
both.

:-)

Cor

Regards - OHM# (e-mail address removed)

Regards - OHM# (e-mail address removed)

Regards - OHM# (e-mail address removed)
 
Back
Top