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

where is gosub

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

    where is gosub

    I have looked enough to believe there is no "gosub".
    Is this correct?
    is there a way to write xbasic with something like
    start:
    gosub this
    gosub that
    eoj:
    end

    this:
    do this
    return

    that:
    do that
    return

    thanks for any thought
    old tony

    #2
    RE: where is gosub

    I believe what you are looking for is GOTO, but I strongly urge you to consider using functions intead of a bunch of goto statements. The spaghetti code created by the gotos will be much more difficult to maintain over time than using function calls in the appropriate places.

    -Lenny

    Lenny Forziati
    Vice President, Internet Products and Technical Services
    Alpha Software Corporation

    Comment


      #3
      RE: where is gosub

      lenny is correct.
      you should use local (or global) functions in your scripts.

      for example

      function fullname as c (firstname as c , lastname as c )
      fullname = alltrim(firstname) + " " +lastname
      end function

      firstname = "tony"
      lastname = "freehauf"
      x = fullname(firstname,lastname)
      ui_msg_box("Hello",x)

      Comment


        #4
        RE: where is gosub

        Sounds like Lenny's too young to remember GOSUB. Unfortunately, I remember it well. But they are right. GOSUB was very similar to a function call - go do this then come back here and continue.

        The 'new' methods will take a bit of getting used to because it's a slightly different thought process but in the long run they are better. (GOSUBs were also very slow.)

        One difference is that a basic function just returns one value - i.e., go get the PO ID and return that value so I can continue:
        "do something>
        po_id = Get_po_from_list( cust_id )
        "keep doing stuff>

        In that example, the cust_id would be "passed" to the function so a list can be generated and the user could select from the list.

        That may not be a great example because it may only be something that is done once. A typical function (just like a GOSUB) would normally be 're-used' multiple times.

        Many other things can be done with functions including passing more variables to them, using "local_variables()", and using "pointer" functions that allow you to return multiple results from one function. (Pointers are a big subject - you'll have to read the help files for more about them.)

        Note about local_variables(): A function can't see any variables defined outside of the function unless you pass them to the function. This is one way of doing that but over-using it is considered bad form because it reduces the portability of functions and can make your app more prone to problems.

        It may not be easy at first but stick with it a bit and I think you will find that it's actually more logical in the long run.

        Cal Locklin
        www.aimsdc.net

        Comment


          #5
          RE: where is gosub

          Sounds like Lenny's too young to remember GOSUB. Unfortunately, I remember it well. But they are right. GOSUB was very similar to a function call - go do this then come back here and continue.

          Actually Cal, I remember gosub all too well. And I don't particularly miss it either.

          I might be younger than some of the other folks around here, but I started programming in 2nd grade. First though they made us learn to count to 100 in binary!

          Lenny Forziati
          Vice President, Internet Products and Technical Services
          Alpha Software Corporation

          Comment


            #6
            RE: where is gosub

            Must be a sign of my age, but when I was coming along we counted from 1 to 100 in roman numerals!

            -- tom

            Comment


              #7
              RE: where is gosub

              You mean you guys know how to count to 100? Jeeez! I never got past 10.
              Peter
              AlphaBase Solutions, LLC

              [email protected]
              https://www.alphabasesolutions.com


              Comment


                #8
                RE: where is gosub

                Yes, but counting to 100 in binary isn't nearly as impressive as counting to 100 in decimal.

                001
                010
                011
                100

                :-)

                Comment


                  #9
                  Re: where is gosub

                  Someone missed the point - local variables in a BASIC program or, if it were implemented, an A5 script can be 'seen' within a GOSUB. User defined functions cannot 'see' variables DIMmed in a script unless they are global - a very dangerous practice. If you want to have some code that, e.g. writes 100fields to a table and you need to call it more than once within a single script then a subroutine (i.e. GOSUB) is ideal. You don't really want to be passing that number of arguments to a function or declaring the variables global. Most versions of BASIC include both GOSUB...RETURN subroutines as well as user-defined functions. I'm sure someone will disagree with me but, hey, humour an old guy brought up on IBM autocoder (that was back in the 60's for information for you youngsters). Lenny seems to have confused GOTO with GOSUB but he is right to say that you shouldn't be using GOTO - very messy.

                  Comment


                    #10
                    Re: where is gosub

                    Roland,
                    User defined functions cannot 'see' variables DIMmed in a script unless they are global
                    I am not that experienced but I do not believe this true what so ever. I run virtually every aspect of my applications with UDF's and don't (almost never)dim variables as global. You must be trying to saying something other than what/how I am reading it.
                    Mike W
                    __________________________
                    "I rebel in at least small things to express to the world that I have not completely surrendered"

                    Comment


                      #11
                      Re: where is gosub

                      Originally posted by rbsystemsdesign View Post
                      If you want to have some code that, e.g. writes 100fields to a table and you need to call it more than once within a single script then a subroutine (i.e. GOSUB) is ideal. You don't really want to be passing that number of arguments to a function or declaring the variables global.
                      No need to pass one value to a parameter. Instead you can pass a pointer to many values. If values are in a table
                      Dim tbl as P
                      tbl = table.open("mytable")
                      tbl.fetch_first()
                      x = myfunction(tbl)
                      passes all the values of the current record in the table.

                      If you want to pass all the variables in the current script
                      Dim vars as P
                      vars = local_variables()
                      x = myfunction(vars)

                      then
                      function myfunction as C (input as P)
                      ...
                      end function
                      Bill.

                      Comment


                        #12
                        Re: where is gosub

                        Mike,
                        Try this:

                        option strict
                        dim blob as c
                        dim blib as c
                        blob = "Hello World"
                        ui_msg_box("Here it is:",blob)
                        blib = blub()
                        end

                        function blub as c()
                        ui_msg_box("Here it is in the function:",blob)
                        end function

                        blob is invisible to the function and before everyone says I need to pass it as a parameter yes, I know. The point is it's a lot more work than a simple gosub which would have gone something like this:

                        dim blob as string
                        dim blib as string
                        blob = "Hello World"
                        print "Here it is:",blob
                        gosub blub
                        end

                        blub:
                        print "Here it is in the subroutine:",blob
                        return

                        blob would have printed.

                        Bill, Thanks. I just think it's more of an effort to use a function than to use a subroutine and apparently vendors of other BASIC compilers agree since they support both subroutines and functions. Each have their place in the programmer's armoury.

                        Comment


                          #13
                          Re: where is gosub

                          Originally posted by rbsystemsdesign View Post
                          option strict
                          dim blob as c
                          dim blib as c
                          blob = "Hello World"
                          ui_msg_box("Here it is:",blob)
                          blib = blub()
                          end

                          function blub as c()
                          ui_msg_box("Here it is in the function:",blob)
                          end function
                          In my mind, XBasic is just using the structural constructs of a higher level language. Don't assume that because the word Basic is in its name that it will have the structures present in most Basics of the past where global variables were assumed no matter how much memory they took up. You made a slight mistake in your first post saying:

                          local variables in a BASIC program...
                          In the first Basics that I used, all variables were created as global - and that's all there was. I have not used Visual Basic for years, but I think that even years ago you had to declare your variables with proper scope to get things to work correctly as well. I know that almost every instructional book on VB from back then strongly discouraged you from using the GoSub construct and suggest that it is only there because of backward compatibility. And also, if memory serves me correct, it is also a very slow method.

                          Your whole example will work with the addition of one simple word. Change the second line to "dim shared blob as c". Now no passing of variables is required. Just like using Option Strict to protect from unwanted dimming of variables, consider dimming shared variables to restrict variables from getting to functions that you have not actively allowed. I personally like having this control and error checking.

                          Comment


                            #14
                            Re: where is gosub

                            Local v Global. In A5 a global variable can be seen by all scripts within the application whereas local cannot. In other BASICs I suppose you could call them global but they were only seen withing the one program (= script) so if you wrote a database application requiring multiple programs a variable in one would not be seen by the others and, in that sense, is local.

                            My recollection is that GOSUB was OK but GOTO was the NoNo.

                            Slow? That's just down to the compiler and machine archtecture. In interpreted BASIC the code has to perform a jump to a point further on in memory and then come back again to the next statement following the gousb and that could be slow. Compiled BASICs tended to optimise the code and the speed of a GOSUB is fine. I never used VB but was brought up on DEC and VAX BASIC, Business BASIC on Data General and a lot of other minicomputer and PC dialects Try PowerBASIC (www.powerbasic.com) which is a current version and see how fast that is and yes, it still does support GOSUB.

                            Thanks for the "shared" tip. Pity the Help file is wrong as usual and implies it can only be used in forms and browses.

                            Comment


                              #15
                              Re: where is gosub

                              Help file is wrong as usual and implies it can only be used in forms and browses
                              Admittedly the help file is not up to date or upkept as well as it should be....but I just read the help file regarding session/shared variables---and read the 3 places that were the most obvious to find---and although only one of them mentioned scripts besides forms/browses, I did not get the same implication as you as a result. I try to not take something out of context and if I only read part of the documentation on something I am hesitant to generalize.

                              I know...I really should get a life outside of Alpha instead of reading the Help files and this messageboard but am just WAY too addicted to having fun!! :)
                              Mike
                              __________________________________________
                              It is only when we forget all our learning that we begin to know.
                              It's not what you look at that matters, it's what you see.
                              Henry David Thoreau
                              __________________________________________



                              Comment

                              Working...
                              X