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

Using a variable as direction for GOTO statement

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

  • Using a variable as direction for GOTO statement

    Does anyone know if/how a variable can be used with a GOTO command? I'm trying to give the user choices in a List dialog to filter a table based various date groups (last week, yesterday, today, tomarrow, current week, next week) and have this choice in a variable direct to a LABEL where the filter would reside. This is likely not possible and I'll probably have to go through a SELECT-CASE series, but I thought I would ask first. A test example that doesn't work is below.

    Code:
    dim vCH as C = "TWO"
    dim vto as C
    
    vto = "GOTO  L" + vCH
    
    Evaluate_template(vto)
    
    LONE:
    MSGBOX("AT ONE", vto)
    
    LTWO:
    MSGBOX("AT TWO",vto)
    
    LTHREE:
    MSGBOX("AT THREE",vto)
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  • #2
    Re: Using a variable as direction for GOTO statement

    Mike,

    The issue is not constructing a GOTO statement using a variable. I'm not sure if it should work or not but it seems that any use of evaluate_template() that affects the flow of the script is ignored. Statements that affect other objects are executed.

    Try this and note that the END command supplied in the variable is ignored.

    Code:
    debug(1)
    
    dim vCH as C = "LTWO"
    dim vto as C
    
    'vto = "GOTO " + vCH
    vto = "END"
    
    evaluate_template(vto)
    MSGBOX("AT ONE", vto)
    end 
    
    LONE:
    MSGBOX("AT ONE", vto)
    resume next
    
    LTWO:
    MSGBOX("AT TWO",vto)
    resume next
    
    LTHREE:
    MSGBOX("AT THREE",vto)
    resume next
    There can be only one.

    Comment


    • #3
      Re: Using a variable as direction for GOTO statement

      In limited testing here it seems that the GOTO statement requires an actual labelname as its argument. If the labelname is in a variable GOTO will interpret the variablename as the labelname and throw an error. The variable is not evaluated, nor is the labelname substituted for the variable at runtime.

      Comment


      • #4
        Re: Using a variable as direction for GOTO statement

        Thanks Tom,

        I'm seeing you are correct. I've wanted this for a long time. OK, I will put this to rest and just use if-then or select-case sequences. It works fine, but just ends up being more coding.
        Mike W
        __________________________
        "I rebel in at least small things to express to the world that I have not completely surrendered"

        Comment


        • #5
          Re: Using a variable as direction for GOTO statement

          Hi Mike,

          When using the evaluate_template, it can't locate any goto labels that are not included in it's arguments.

          If you set a variable to the evaluate_template(), you'll see that that variable will return the error for the evaluate_template. The code for the evaluate_template() must have it's own internal error handler if desired.

          So when using evaluate_template, use it like this

          Code:
          result=evaluate_template(code_in_variable)
          IF .not.(result=="")
          ' result contains text error, e.g. "Can't locate that symbol" for your case
          end if
          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


          • #6
            Re: Using a variable as direction for GOTO statement

            Ira,
            Sorry, but you lost me.

            I'm not trying to error trap an evaluate_template() result, I'm trying to use a variable as the LABEL NAME for the GOTO statement in xbasic script. Possible?

            Code:
            dim vLabel as C = "TESTLABEL"
            
            GOTO var->vLabel
            END
            
            TESTLABEL:
            msgbox("made it here")
            Mike W
            __________________________
            "I rebel in at least small things to express to the world that I have not completely surrendered"

            Comment


            • #7
              Re: Using a variable as direction for GOTO statement

              Hi Mike,

              All goto and labels have to be in the variable that is used in the evaluate_template input, as in
              Code:
              dim vCH as C = "TWO"
              dim vto as C
              
              vto ="GOTO  L" + vCH+crlf()+<<%code%
              
              LONE:
              MSGBOX("AT ONE", vch)
              end
              
              LTWO:
              MSGBOX("AT TWO",vch)
              end 
              
              LTHREE:
              MSGBOX("AT THREE",vch)
              
              %code%
              
              ' notice that vto is just one long string 
              ' with multiple lines of code
              rslt=Evaluate_template(vto)
              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


              • #8
                Re: Using a variable as direction for GOTO statement

                Ira,

                Thank you very much for explaining that. So, OK, no way is evaluate_template going to work for me since some of my scripts have numerous episodes of List-List dialog for user choices throughout the script and many sequences of direction and re-direct. The code-within-code-within-code would be unresolvable, at least to this man. I'll stick with what's working, albeit needing more coding, and ask for something more simple as a wishlist.

                Thanks again.
                Mike W
                __________________________
                "I rebel in at least small things to express to the world that I have not completely surrendered"

                Comment


                • #9
                  Re: Using a variable as direction for GOTO statement

                  Hi Mike,

                  Not sure if this will result in any less coding in your context than a select-case structure but does make code quite flexible. I think you can do without the local_variables if you make the variables in the main script shared but include it here just for the example. Hopefully Ira will comment and correct any errors.

                  Code:
                  dim vCH as C = "two"
                  dim  vto as C = "xxx"
                  dim vl as p
                  
                  vl = local_variables()
                  
                  Evaluate_template(vch+"(vl)")
                  
                  
                  FUNCTION one as V(vl as p)
                      with vl
                      MSGBOX("AT ONE",vto)
                      end with
                  END FUNCTION
                  
                  
                  FUNCTION two as V(vl as p)
                      with vl
                      MSGBOX("AT TWO",vto)
                      end with
                  END FUNCTION
                  
                  
                  FUNCTION three as V(vl as p)
                      with vl
                      MSGBOX("AT THREE",vto)
                      end with
                  END FUNCTION
                  Tim Kiebert
                  Eagle Creek Citrus
                  A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                  Comment


                  • #10
                    Re: Using a variable as direction for GOTO statement

                    Tim,
                    Quite interesting! It replaces LABEL segments with Function segments. I'll keep this in mind, for sure. Thanks!
                    Mike W
                    __________________________
                    "I rebel in at least small things to express to the world that I have not completely surrendered"

                    Comment


                    • #11
                      Re: Using a variable as direction for GOTO statement

                      Mike,

                      I had this old thread in the back of my mind re using functions instead of goto. I don't think I have used a goto since reading it.
                      Tim Kiebert
                      Eagle Creek Citrus
                      A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                      Comment


                      • #12
                        Re: Using a variable as direction for GOTO statement

                        Tim,
                        Thank you for that link. It will take me a while to digest all that as it contains some pretty high level understandings that don't immediately jump off the page to me. I'm not immediately seeing how I would replace all the GOTO processes I use with this approach, but I'm going to work on it, as I am sensing making that transition will enrich my current level of scripting knowledge and efficiency.

                        One thing is pretty certain though, is that my wishlist item for a function to use a variable as a label pointer for GOTO statements isn't going to get much consideration from those that consider GOTO as not having much purpose and working to replace it's utility, huh?
                        Mike W
                        __________________________
                        "I rebel in at least small things to express to the world that I have not completely surrendered"

                        Comment


                        • #13
                          Re: Using a variable as direction for GOTO statement

                          Originally posted by Mike Wilson View Post

                          One thing is pretty certain though, is that my wishlist item for a function to use a variable as a label pointer for GOTO statements isn't going to get much consideration from those that consider GOTO as not having much purpose and working to replace it's utility, huh?
                          As Bill Murray so apply put in "Stripes", "That's a fact, Jack!"... ie yes, use the functions method as described. Sometimes we like to use our own way of doing things instead of the way of the programming model. Those that fight the model suffer long and hard battles that they likely lose. You have made a wise choice, grasshopper... (Someone back a long ways a go said that....)
                          Al Buchholz
                          Bookwood Systems, LTD
                          Weekly QReportBuilder Webinars Thursday 1 pm CST

                          Occam's Razor - KISS
                          Normalize till it hurts - De-normalize till it works.
                          Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                          When we triage a problem it is much easier to read sample systems than to read a mind.
                          "Make it as simple as possible, but not simpler."
                          Albert Einstein

                          http://www.iadn.com/images/media/iadn_member.png

                          Comment


                          • #14
                            Re: Using a variable as direction for GOTO statement

                            Hi Mike,

                            As Al said, your wish list request will never happen. There is really no use I can imagine that would be better served by your desired method. But let's go back to your original problem that you are trying to accomplish.

                            Originally posted by Mike Wilson View Post
                            I'm trying to give the user choices in a List dialog to filter a table based various date groups (last week, yesterday, today, tomarrow, current week, next week) and have this choice in a variable direct to a LABEL where the filter would reside. This is likely not possible and I'll probably have to go through a SELECT-CASE series, but I thought I would ask first. A test example that doesn't work is below.
                            From the above, it sound like that you have a list of items that you want to select the corresponding filter to the selected item. This is just a matter of getting the list position of 1, and then returning the list item 2. This is accomplished simply and has more expandability something like this:

                            Code:
                            list1=<<%text%
                            red
                            white
                            blue
                            green
                            orange
                            %text%
                            
                            list2=<<%text%
                            filter 1
                            filter 2
                            filter 3
                            filter 4
                            filter 5
                            %text%
                            
                            selected="blue"
                            
                            filter_selected=word(list2,wordat(selected,list1,crlf()),crlf())
                            
                            ui_msg_box("Select Result","Select:"+selected+crlf()+"Filter:"+filter_selected)
                            end
                            A similar method can also be done with arrays instead of lists.
                            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


                            • #15
                              Re: Using a variable as direction for GOTO statement

                              There is one more little 'facet' about goto labels.....
                              If you are using XDialog with %dlg% ... some code ....%dlg%,%code% .... and try to use a goto command within the %code% section ---- the label MUST ALSO BE within the %code% section. Then if some other action is required once you leave the %code% section, you can assign a value to a variable or flag before you leave the section. Alpha cannot see outside the XDialog segments. It is really not a problem once you find this out and write your code appropriately. Using a goto label is one way to quickly exit from select clauses without having to process all of the clauses.

                              D

                              Code:
                              %dlg%
                              ......
                              %dlg%,%code%
                              if a_dlg_button= "OK" then
                              goto area1
                              end if
                              ...
                              ..
                              ...
                              ...
                              area1:
                              
                              %code%
                              
                              .....
                              etc

                              Comment

                              Working...
                              X