[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Can Several Form instances change Module Array

Posted on 1999-01-18
2
Medium Priority
?
217 Views
Last Modified: 2010-05-03
I have a program that creates several instances of a form.
I also have a Module which includes a global array so as to allow all of the instanced forms to have access to.

My question is: What happens when several forms try to access AND change that array? Can 2 or more instanced forms access the same indexed area of an array and change it or does windows intervene and prevent another form from changing this array while another is working on it (and once done it allows the other to do whatever it wants to it as well)?  

I was thinking of accessing this global array inside the form itself like so:

private sub form_load()
 Global_Array(0)= Global_Array(0) & "Hello" 'Global_Array() is defined in Module1.bas
 Global_Array(1)=  Global_Array(0) & Global_Array(1) & "Hi"
 Global_Array(2)= Global_Array(0) &  Global_Array(1) &  Global_Array(2) & "Aloha"
end sub

BUT if i have several instances that are also created and who also change this global array i am wondering if it gets really messy or does windows halt an instance while another instance is working on the same index area of an array.

If it is messy then what about this idea: I place a procdure inside the Module1.bas file which includes an argument to the form object. With this i now know who is calling me and say maybe i have a static variable which tells me which form was in here last and if it isn't set to NULL then that tells me someone is still in here and so i should go into an infiinite loop until this static variable is set back to NULL.  Take a look:

public sub Change_Global(thisform as form1)
  static lastform as form1

  if lastform <> Nothing then
     do
       DoEvents
     loop until lastform = Nothing
  endif
  Set lastform = thisform

 Global_Array(0)= Global_Array(0) & "Hello"
 Global_Array(1)=  Global_Array(0) & Global_Array(1) & "Hi"
 Global_Array(2)= Global_Array(0) &  Global_Array(1) &  Global_Array(2) & "Aloha"
 
   Set lastform=Nothing
end sub


Hope this makes sense..If there is a better way or i am completely off or just plain idiotic please let me know. I am interested to find out what is the best solution.
0
Comment
Question by:ljaques
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 40 total points
ID: 1469206
There is no problem doing all that. You can have multiple instance of a form that access a single public variable (or array) in a module. Window and VB handle that for you.

But a better solution can be to encapsulate by making your array as private and making public methods (sub or function) to deal with your array (that becomes a property).

If you whish to be purist, look at the class object.

0
 

Author Comment

by:ljaques
ID: 1469207
thanks very much emoreau...those were the wonderful words i was looking for.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question