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

Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

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

    Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

    Hello -

    Last week, I needed to learn how to take a series of fields, build a concatenated string, and stuff it into a field in my table (so I could use it in various views/reports without having to re-build the string each time).

    Steve Workings taught me to build it in: Code.Server-SideEvents.CanUpdateRecord

    This works, but only for records that I am updating.
    So I'm copying the same code into Code.Server-SideEvents.CanInsertRecord

    My Question is: I'm pretty sure there is some way I can have the code in 1 place (the scrapbook? the code library?) and use it in both the CanUpdateRecord and CanInsertRecord

    so that if I need to alter the concatenation formula, I'm only having to do it in one place, not two.

    Can someone point me to what I need to learn to do this?

    Thanks
    MSQL since 2010
    A5V11 since Feb 2012

    #2
    Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

    Create a global UDF - or as many as you need and when you publish check off "Compile functions into an.AEX file". Then your functions will be universally available throughout your app.
    Peter
    AlphaBase Solutions, LLC

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


    Comment


      #3
      Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

      Thank you Peter - I think I'm getting close, but not at home plate.

      1. I have what I think is a global udf, created in the Code Editor and saved as a Function.
      FUNCTION DateDueTermsText AS C ( )

      dim txt as c = ""

      if (val(DataSubmitted.Numerator) / val(DataSubmitted.Denominator)) <> 1 then

      txt = "" + DataSubmitted.Numerator + chr(47) + DataSubmitted.Denominator + ": "+DataSubmitted.PhaseQualifier1

      else

      txt = "" + " blah blah blah"

      end if

      DataSubmitted.TermsText = txt

      END FUNCTION
      2. In the component where I'm trying to get this to appear, I:
      - set the Control Type as Custom
      - set Custom Control Property as: TermsText_Render = DateDueTermsText()
      - set GridProperties.Miscellaneous.Xbasic.aex file set as Databasename.aex

      3. I publish the web project, toggling on 'compile functions into an .aex file'

      4. When I launch in a browser, I'm getting the following error when I attempt to update a record or insert a record into the table associated with the grid component that utilizes the Custom Control:

      Error in custom control xbasic: not found Data Submitted not found



      so, what does this tell me... seems to me that the UDF doesn't know how to talk to the component to find out the specific field data? or ????
      MSQL since 2010
      A5V11 since Feb 2012

      Comment


        #4
        Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

        Your function needs to return a value like this:

        Code:
        FUNCTION DateDueTermsText AS C ( )
            txt = "whatever you need to assign to txt"
            DateDueTermsText = txt
        End Function
        Then, in your CanInsertRecord event, you do this:

        Code:
        DataSubmitted.TermsText = DateDueTermsText()
        -Steve
        sigpic

        Comment


          #5
          Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

          @Steve -

          Thank you; I had written an email to you about this, but decided to see if I could solve it at the forum without bothering you - I know you had mentioned this when we spoke, and I 'blew it off' because I wasn't ready ...

          I've now adjusted the CanInsertRecord event, as well as the CanUpdateRecord event....

          and I have changed the TermsText Field back to being a text control (not a custom control, as explained in the video)

          Ok - that seems to have gotten me a bit closer, altho now I have an error message on the inserts and on the update....


          Error executing CanUpdateRecord event handler: command: if (val(DataSubmitted.Numerator) / val(DataSubmitted.Denominator)) <> 1 then Not found
          DataSubmitted not found.



          OK. Let's KISS - I've stripped away the If...Else... Endif
          and I''m still getting errors:
          Error executing CanUpdateRecord event handler: command: txt = "" + DataSubmitted.Numerator Not found
          DataSubmitted not found.


          If this is too complicated by forum, can you shoot me an email and we'll find a time when you can show me by TeamViewer?
          MSQL since 2010
          A5V11 since Feb 2012

          Comment


            #6
            Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

            Better to answer it here if possible Marion because I'd like to know the answer too :)

            Comment


              #7
              Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

              There are probably a couple ways to do this. Code example first:

              CanInsertRecord:
              Code:
              function CanInsertRecord as v (DataSubmitted as P, Args as p, PageVariables as p, Result as p)
              with PageVariables
              Result.Cancel = .f.
              Result.ErrorHTML = ""
              
              	DataSubmitted.DESCRIPTION = DataSubmitTest(DataSubmitted)
              
              end with
              end function
              User Defined Function:
              Code:
              FUNCTION DataSubmitTest AS C (DataSubmitted as P)
              
              	dim new_Description as c = ""
              	new_Description = "Test: " + DataSubmitted.DESCRIPTION
              	DataSubmitTest = new_Description
              	
              END FUNCTION
              I think the most important point worth explaining is that the UDF didn't "see" the DataSubmitted. OK, you knew that, but what to do about it? You can see that the Event already contains DataSubmitted as a Pointer variable, and since the UDF wasn't seeing it -- but we need it -- we need to pass the Pointer variable and all its values into the function. By doing this, all the DataSubmitted values are now available.

              If I haven't explained this well enough or I need to detail this more, let me know.
              -Steve
              sigpic

              Comment


                #8
                Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

                Hi Steve -
                Ok.... I am implementing as a test, and.... super - it works.

                Now I'll see if I can factor in some of the actual field data, not just the word 'test'

                super - that works too (altho, it seems I have to have all the parts of the concatenation on one long line)

                Now let me see if I can do the update....yep - that works too

                excellent excellent excellent.

                Thank you!
                MSQL since 2010
                A5V11 since Feb 2012

                Comment


                  #9
                  Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

                  There's nothing "wrong" with long code lines for the concatenation, but there are other ways too. Here's one:

                  Code:
                  dim myNewVal as c = ""
                  myNewVal = "This is the first part of the sentence " 
                  myNewVal = myNewVal + " and then I added in this value " + datasubmitted.something
                  myNewVal = myNewVal + " along with more like this " + datasubmitted.somethingelse
                  myNewVal = myNewVal + " and if I want a crlf I can add that in like this. " + crlf()
                  -Steve
                  sigpic

                  Comment


                    #10
                    Re: Reusing lines of Xbasic in multiple events; Scrapbook? Code Library?

                    got it

                    I figured there was a way.

                    Makes it easier to read/edit when it is broken up onto several lines
                    MSQL since 2010
                    A5V11 since Feb 2012

                    Comment

                    Working...
                    X