Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Loosing Global Variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Loosing Global Variables

    I have several global variables declared in my main Program. The main Program (form) is always open. All forms and functions are opened from the main menu, no global variable are declared anywhere other then in the main Program (form).

    The program runs in a network environment.

    I am experiencing the loss of my global variables: I get the following error code: Variable "Current_Stocknum" not found. - How can this variable not be found when it is global and used through out the program. (this is happening to several variables)

    What could be causing this and how can I prevent it?

    #2
    Re: Loosing Global Variables

    Are you using the statement

    dim global Current_Stocknum

    in all scripts that use the variable?

    Using that statement tells the script that you mean to reference the global variable. Otherwise Alpha may assume that you are referencing a different instance (scoped differently) in the present script. Generally this doesn't happen but it can.

    Using that dim statement does not change the value of Current_Stocknum, just provides explicit reference to it.
    There can be only one.

    Comment


      #3
      Re: Loosing Global Variables

      Visit one of your forms or reports and explicitly dimension the global again before assigning current value to it. Does the error go away?

      Comment


        #4
        Re: Loosing Global Variables

        Stan - I will try your suggestion and see what happens

        Tom - When I dim the same variable global in one of the other forms - the program seems to get confused and doesn't set the values right that is why I only use my main form for all global variables.

        Comment


          #5
          Re: Loosing Global Variables

          Interesting. Stan and I told you the same thing in different ways.

          I think you'll find you must "dim" the global variable each time you want to refer to it in a form or script.

          The rule I follow here is that each script I write will treat variables as "local" to the script unless explicitly "dimensioned" to a different scope. Alpha Five permits the same variable "name" to be used in "local", "shared" and "global" name spaces; all at the same time. Explicitly "dimensioning" the variable as global in my script helps Alpha Five determine which name space to use.

          Comment


            #6
            Re: Loosing Global Variables

            Tom,

            I am now confused. I dim anywhere from 5 to 35 global variables in autoexec script and have never re-dimmed one for any reason. Some are always there for reading purposes and others are changed progrmatically sometimes, but never redimmed.

            explian:
            dim global gmyvarname as c
            and in another script:
            var->gmyvarname = "some value"
            I am always being careful to not use the same names for local, shared vars.

            usually my globals are started with a "g" so I don't make a mistake.

            Is this not supposed to work?

            Comment


              #7
              Re: Loosing Global Variables

              Ok.

              Have you bothered to actually try our suggestions?

              .... Tom

              Comment


                #8
                Re: Loosing Global Variables

                Sorry Tom,

                I did not mean to offend anybody and no. I have had no reason as yet. Well, maybe I should keep it in a drawer somewher until a problem occurs?

                Thanks

                Comment


                  #9
                  Re: Loosing Global Variables

                  Originally posted by VWitter001 View Post
                  The program runs in a network environment.
                  All variables are Local (not as in a local variable but local as in localized to) each machine.

                  Comment


                    #10
                    Re: Loosing Global Variables

                    dimming global variables in, for example, autoexec is sufficient; however, when using the variables later, under certain circumstances, will require redimming them.

                    For example, if you used tablecount(), and used a global variable, you may need to redim it, otherwise it may not be acknowledged in the function.

                    Note: when you redim, you don't reset the value - just say dim global xxx as c.
                    Cole Custom Programming - Terrell, Texas
                    972 524 8714
                    [email protected]

                    ____________________
                    "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

                    Comment


                      #11
                      Re: Loosing Global Variables

                      Hi Al,
                      Originally posted by amorris View Post
                      Tom,

                      I am now confused. I dim anywhere from 5 to 35 global variables in autoexec script and have never re-dimmed one for any reason. Some are always there for reading purposes and others are changed progrmatically sometimes, but never redimmed.

                      explian:
                      dim global gmyvarname as c
                      and in another script:
                      var->gmyvarname = "some value"
                      I am always being careful to not use the same names for local, shared vars.

                      usually my globals are started with a "g" so I don't make a mistake.

                      Is this not supposed to work?
                      If gmyvarname and var->gmyvarname are synonymous names. As long as both uses are either explicitly dimmed globally, or explicitly dimmed by alpha code (by setting a global variable on a form), they should always work, UNLESS you have a local or shared variable with the same name in the current thread

                      I cover the issues with dimensioning variables in my Variable Usage, Dimensioning & Deletion tips

                      I ran a quick check, and I use about 26000 dim's in 850 general functions I have created over time. No variable is ever implicitly dim'ed and globals and shared are always very uniquely named, variable deletions are limited to very special cases and as a result, I have never, repeat, NEVER, had a variable collision in Alpha Five.
                      Regards,

                      Ira J. Perlow
                      Computer Systems Design


                      CSDA A5 Products
                      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                      CSDA Barcode Functions

                      CSDA Code Utility
                      CSDA Screen Capture


                      Comment


                        #12
                        Re: Loosing Global Variables

                        Along with what Ira said, and I am sorry, but in opposition to the "Redim" Team, if you dim a variable as global, you should never have to "Red1im" it during the entire session. That's the whole essence of being global.
                        Few remarks:
                        1-For as long as I have used alpha, I never redimmed anything.
                        2-Looking at the help file for Redim which I haven't visited in a while, it is meant to redim an array. As you know, arrays have to be dimmed, and subsequently redimmed, explicitly.
                        3-I think the crux of this matter is: at what point the variable has been actually dimmed.
                        What Virginia needs to do, first and foremost, is to determine, not assume, that the variable has actually been dimmed before further assuming that it has and has been lost.

                        Comment


                          #13
                          Re: Loosing Global Variables

                          Originally posted by G Gabriel View Post
                          Along with what Ira said, and I am sorry, but in opposition to the "Redim" Team, if you dim a variable as global, you should never have to "Red1im" it during the entire session. That's the whole essence of being global.
                          I don't think Martin means redim as in the command directive REDIM, but insteads means that it should be dim'med in all threads prior to 1st use. Using extra DIM doesn't add much overhead, and you can use it even if the variable was previously DIM in the code, if you DIM it the same type and size (setting of original and default values can be different though). In fact, all code should do a DIM before usage to make sure it's scope is correct.

                          As for redim usage myself, I have looked at my usages in code I have, and it was used in other client code and in just 1 or 2 places in my own code. I believe there was one case where I actually had to use it over other alternatives, but couldn't find it. In speed testing, it was fastest to redim, a little slower to delete and dim, and slowest to resize for an array.

                          The best reason I can imagine for a redim is to change type or an array's size or # of dimensions. However, good multi-thread coding practice would never change a variable type or size/dimensions, unless specific to the code and also a local variable, or at least account for access to the variable if sharing between multiple threads. Basically, it's for the same reason's you should never do a delete (without a real good reason) of shared or global variables.

                          One really good reason to delete/resize/redim an array is that it is very large (I'm saying like 500000+ in # of elements, and you want to return the space to main memory), or you are looping and processing variables of changing types and need to adapt the code to each type but this is rare for most code, although very common in utilities. In either case, variable should still be local.
                          Regards,

                          Ira J. Perlow
                          Computer Systems Design


                          CSDA A5 Products
                          New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                          CSDA Barcode Functions

                          CSDA Code Utility
                          CSDA Screen Capture


                          Comment


                            #14
                            Re: Loosing Global Variables

                            No apology necessary Al.

                            I mistook you for the original poster. Was using a small tablet to view the thread and lost track of who was speaking to whom, so to speak !

                            -- tom

                            Comment


                              #15
                              Re: Loosing Global Variables

                              G, I'm afraid I agree with Ira (this time!). Best practice is to DIM the variables each time they're used. By specifying the "scope" each time all ambiguity is removed. No more wondering if the var is local, shared, or global. Maintenance of scripts later on is simplified.

                              Comment

                              Working...
                              X