Re: Global User Defined Array?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Justin Emlay (JEmlay_at_Maisto[NOSPAM)
Date: 03/19/04


Date: Fri, 19 Mar 2004 11:57:28 -0800

Thanks for the heads up Mike. Been programming for about 2 years now. So
far I've never had to make a User Defined Array global. So I guess I'm
already adhering to those standards. When you start down the trail of
global variables you wind up with too many variables in the whole project
since you obviously aren't reusing them. The most common descriptions
anyway. In this case though I only needed one array to be global. I needed
Form1 to build the array, then I needed Form2 to be able to access that
data. During the scope of the entire project I access that array a lot so
this was the best/fastest method to give me what I want.

I could have avoided this by implementing tabs but then my toolbar would
have been junked up and too large (each form has a different toolbar).
Grayed out toolbar items looks tacky if you ask me.

"MikeD" <nobody@nowhere.edu> wrote in message
news:%231XikZVDEHA.576@TK2MSFTNGP11.phx.gbl...
> Just a heads-up since you're apparently new to VB (and it also sounds like
> programming in general)....
>
> Global variables can be EASILY over-used. Don't start making a lot of
your
> variables global for "convenience" or whatever other reasons. If you do,
> you're inevitably going to get into a LOT of trouble down the road (i.e.
> hard to read code; bugs that may be difficult to track down and even
harder,
> or at least time-consuming, to correct, etc.).
>
> I'm not saying global variables don't have their purpose and usefulness,
nor
> that they should never be used. Just be sure you're ONLY using them when
> the variable TRULY needs to be global. For most beginners, this
distinction
> (knowing when you should use a global and when you shouldn't, which goes
> along with knowing what you can alternatively do instead of using the
> global) is difficult to make and even understand. With experience, you'll
> discover that a genuine need for a global variable is actually fairly
rare.
> There are usually alternatives (such as making the global variable a
Public
> Property of a form, which provides encapsulation).
>
> Mike
>
>
>
>
> "Justin Emlay" <JEmlay@Maisto[NOSPAM].com> wrote in message
> news:4059f2e5$0$31672$c3e8da3@news.astraweb.com...
> > Thanks Al Reid, that did the trick!
> >
> >
> > "Al Reid" <areidjr@reidDASHhome.com> wrote in message
> > news:e95CflRDEHA.2804@tk2msftngp13.phx.gbl...
> > > Try making the TestArray Public:
> > >
> > > Type TestType
> > > test As String
> > > End Type
> > >
> > > Public TestArray(10) As TestType
> > >
> > >
> > > --
> > > Al Reid
> > >
> > > "It ain't what you don't know that gets you into trouble. It's what
you
> > know\\for sure that just ain't so." --- Mark Twain
> > > "Justin Emlay" <JEmlay@Maisto[NOSPAM].com> wrote in message
> > news:4059eb30$0$31665$c3e8da3@news.astraweb.com...
> > > > I tried moving it to a module:
> > > >
> > > > Global.bas:
> > > >
> > > > Type TestType
> > > > test As String
> > > > End Type
> > > > Dim TestArray(10) As TestType
> > > >
> > > >
> > > > Form1:
> > > >
> > > > Private Sub Form_Load()
> > > > TestArray(0).test = "This is a test"
> > > > End Sub
> > > >
> > > > Error:
> > > > Sub or Function not defined.
> > > >
> > > > What am I doing wrong?
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: Using collection to store variable values
    ... store variables rather than declaring Global Variables. ... and a value or a key (to retrieve the value). ... that functionality is working fine in the test program I've developed. ... The problem with using an array is that you either have to keep track of ...
    (microsoft.public.access.formscoding)
  • Re: Globals vs passing in by reference
    ... >hold this array. ... Then they increment the global int variable. ... >function or just access the global variables? ... probably) and the counter has a cost in ...
    (comp.lang.c)
  • Re: Using collection to store variable values
    ... store variables rather than declaring Global Variables. ... and a value or a key (to retrieve the value). ... that functionality is working fine in the test program I've developed. ... The problem with using an array is that you either have to keep track of ...
    (microsoft.public.access.formscoding)
  • Re: passing data to functions in other units
    ... > From what j said each unit can access the global variables provided the ... >> There are three passing mechanisms in Delphi that you should consider. ... The routine is therefore working with the ... >> array to find the middle value and didn't want to sort the passed array, ...
    (alt.comp.lang.borland-delphi)
  • Re: passing data to functions in other units
    ... From what j said each unit can access the global variables provided the ... var the same as a pointer? ... > because of a poorly choosen passing mechanism;). ... >>The global variable i have is a static array of bytes. ...
    (alt.comp.lang.borland-delphi)