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

Script Variable in a Loop

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

    Script Variable in a Loop

    Does anyone know if it is possible to have a variable inside a variable name?
    I have a collection of variables from a dialogue script, call them %A1, %A2, %A3, etc.
    Inside my loop I want to have this %A# variable count up with each loop, so that loop 1 pulls %A1, loop 2 uses %A2 and so on.
    The loop works, so I don't need help with that, I'm trying to re-purpose it for something else and need this capability.
    Thanks in advance for any help.

    #2
    Re: Script Variable in a Loop

    Not really sure what your question is but as best as I can figure this should do what your asking.

    Code:
    DIM vVar1C as C
    DIM vVar2C as C
    
    vVar1C = "vVar2C"
    
    vVar2C = "Random value"
    
    ?vVar1C
    = "vVar2C"
    
    
    ?eval(vVar1C)
    = "Random value"
    
    ?eval("vVar2C")
    = "Random value"
    Andrew

    Comment


      #3
      Re: Script Variable in a Loop

      Andrew - Thanks for the reply.

      Your code doesn't look like the Alpha 4v8 scripting language so I'm not sure how to use it.

      What I was looking to do was call a set of sequentially numbered variables populated with values in a in dialogue script. I'm writing a script for batch record creation. This sequential variables contain ID numbers that are already in the database. The loop creates a service record for each of these items using a set of fixed variables also populated in the dialog script (date, tech, etc.).

      What I end up with is a series of sequentially number variables with ID tag values in them.
      %ID1 426587
      %ID2 421853
      %ID3 863586

      The script can enter data for each of these IDs by looping, but I couldn't figure out a method for having the %ID variable be a variable itself. On the first pass it needs to be %ID1, second should be %ID2 and third should be %ID3.

      I'm looking for something that would make a character in a variable name a variable in itself, that way I can have....
      VARIABLES: %N=3, ID's are those listed above, %SVCTECH=BOB, %SVCDATE=08222013
      SCRIPT:
      {SET %X,"1"}
      {:A}
      {FIELDENTER "SERVICE->ID", (%ID(%X))}
      {FIELDENTER "SERVICE->DATE", %SVCDATE)}
      {FIELDENTER "SERVICE->TECH", %SVCTECH}
      {SET %X,VAL(%X)+1}
      {LOOP :A, %N}

      Thereby creating a service record for each ID number.

      Comment


        #4
        Re: Script Variable in a Loop

        oof; sorry didn't see you had posted in the v4 forum only noticed the version 8 bit.
        Andrew

        Comment


          #5
          Re: Script Variable in a Loop

          I wasn't able to find a way to accomplish this, but I was able to find a way around it.

          I saved all of the variables into one long string and then use the SUBSTR function to select the desired characters from the string (up to 256 characters). In my case this wasn't that complicated because each variable is a known number of characters, 6 in this case, so all I needed to do was make the starting character a variable.

          Dialogue Script provides %N for number of loops(and thereby variables) and all of the variables themselves (%VRB1, 2, 3, etc.).

          {SET %VRbALL,%VRB1+%VRB2+%VRB3+....+%VRB15}
          {SET %NVRB,"1"}
          {:A}
          {SET %VRB,(SUBSTR(%VRBALL,VAL(%NVRB),6))}
          {FIELDENTER "DATABASE->FIELD",%VRB,%VRB_ERR}
          {SET %NVRB,VAL(%NVRB)+6}
          {LOOP :A, %N}

          A note about using Variables inside Expressions - Section 23-10 in the A4v6 reference manual covered a problem I hit regarding the fact that when using a script variable in an expression it will always be treated as a character variable/string, ignoring how the variable may be treated outside of the statement. This means that if the expression is expecting a number, as the SUBSTR expression does for the starting character and number of characters to copy values, you must convert the variable to number with the VAL statement inside the expression even if you have already done so outside the statement. This cost me a few hours. {SET %VRB,(SUBSTR(%VRBALL,VAL(%NVRB),6))}

          I can envision several improvements on this script that aren't needed for my application but I will mention just in case they are useful for someone else.
          1) You could evaluate the contents of each variable (%VRB1, %VRB2, etc.) to determine which are not blank and determine the value of %N instead of relying on user entry.
          2) You could have a variable length variable, as we as a variable number of variables. (that was clear as mud, right?) If you evaluated each %VRB# variable with LEN(TRIM(%VRB#)) then you could adapt the same process described above to create and establish a string of characters detailing the length of each variable string. You could then use those values to calculate out the changing start point and number of characters in the SUBSTR statement. I'm not going to provide more detail on this as it's a lot of work that I don't need to do, but I hope that helps you if you have to try it out.

          Comment


            #6
            Re: Script Variable in a Loop

            Hi Bo,

            To do indirection in Alpha 4, you place the variable name within braces, as in {%varnam}

            Whatever value is in the string varname, will be executed as if it was alpha four script code located right there in the rest of the code.
            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


              #7
              Re: Script Variable in a Loop

              Ira,

              Thanks for the response.
              I've didn't have any luck getting this to work.
              Here's one variation of the test script that I created for this - it errors out.

              {SET�%TVAR1,1234}
              {SET�%TVAR2,5678}
              {SET�%NTEST,1}
              {SET�%TVAR,{%TVAR{%NTEST}}} <--- this is trying to set %TVAR to %TVAR1
              {SET�%NTEST,2}
              {SET�%TVAR,{%TVAR{%NTEST}}} <--- this is trying to set %TVAR to %TVAR2

              This sets %TVAR to "%TVAR{%NTEST}"

              I'm not clear on how, in your example I can modify the string (varname) with a variable.

              Comment


                #8
                Re: Script Variable in a Loop

                Hi Bo,

                Originally posted by BoRoche View Post
                Ira,

                Thanks for the response.
                I've didn't have any luck getting this to work.
                Here's one variation of the test script that I created for this - it errors out.

                {SET�%TVAR1,1234}
                {SET�%TVAR2,5678}
                {SET�%NTEST,1}
                {SET�%TVAR,{%TVAR{%NTEST}}} <--- this is trying to set %TVAR to %TVAR1
                {SET�%NTEST,2}
                {SET�%TVAR,{%TVAR{%NTEST}}} <--- this is trying to set %TVAR to %TVAR2

                This sets %TVAR to "%TVAR{%NTEST}"

                I'm not clear on how, in your example I can modify the string (varname) with a variable.
                I probably didn't clearly describe the method, however, the macro interpreter substitution does not work inside a command statement where it is interpreted as data, e.g. a {SET ...} command. It will work inside an {IF ...} statement
                so if you had
                {SET %var1,"{F2}"}
                {%var1}
                it will place {F2} where{%var1} is

                In an IF statement

                {SET %var1,"{F2}"}
                {IF %var2=%var3,{{%var1}ABC},{{MAINMENU}}}

                would do an {F2}ABC if true.

                Substitution for keys in an ONKEY and other type events, have a different issue. They place the keys into the keyboard buffer and are played back only when the keyboard gets control, which can be tricky to do right.

                Hope this helps.
                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


                  #9
                  Re: Script Variable in a Loop

                  Ira - thank you again for your time.

                  I don't think this addresses what I'm trying to do as I would still need to have a statement for each iteration of the variable.

                  I have 15 variables entered in a dialogue script, %ID1, %ID2... %ID15.
                  What I want to do is write a loop that cycles through all of these variables by calling a different one during each loop.

                  In it's most basic form...
                  {SET %N,15}
                  {:A}
                  {SET # from %ID#, to %N} <----- Bogus code just get convey the idea
                  {FIELDENTER "DATABASE->FIELD",%ID#,%ID_ERR} <----- In this case the # of %ID# would count down from 15
                  {LOOP :A, %N}

                  In a modern database application I would place the 15 records in a temp table and code the script to run through all the records in the table, but I don't think that's an option here. That's effectively what I've done in the somewhat cumbersome method from my 8/26/13 post. I use the variables to create what is essentially a fixed width DBF inside a string variable and then parse out the data from it. It just seems that there would be some way to create a variable with a variable element inside of it or at least one that will count up or down through an array of variables with a common naming structure.

                  Thanks again. I hope I'm missing something.

                  Comment


                    #10
                    Re: Script Variable in a Loop

                    Hi Bo,

                    Originally posted by BoRoche View Post
                    {SET %N,15}
                    {:A}
                    {SET # from %ID#, to %N} <----- Bogus code just get convey the idea
                    {FIELDENTER "DATABASE->FIELD",%ID#,%ID_ERR} <----- In this case the # of %ID# would count down from 15
                    {LOOP :A, %N}
                    I haven't checked this code, but it should look something like

                    {SET %N,15}
                    {:A}
                    {* this builds a string that looks like the desired fieldenter string *}
                    {set %tmp,"{FIELDENTER "+chr(34)+"DATABASE->FIELD"+chr(34)+",%ID"+%N+",%ID_ERR}"}

                    {* this executes the code in the string %tmp *}
                    {%tmp}
                    {LOOP :A, %N}
                    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


                      #11
                      Re: Script Variable in a Loop

                      10,000 points to Ira!

                      Thank you, sir. That works. Your original statement - "Whatever value is in the string varname, will be executed as if it was alpha four script code located right there in the rest of the code." told me everything I needed to know, but I didn't know enough at the time to interpret it correctly. Thank you for your time an patience.

                      For the record, here's the script I wrote to test this out.
                      %TVAR# variables are the values I want to use to update the %VAR variable to a new value in each loop. In a real world example they would be populated by user input in a Dialogue Script that calls this Keystroke Script. I've included them in this Keystroke Script for simplicity's sake.
                      %VAR is the variable used inside the loop that gets updated with the %TVAR# values. In a real script this could be used, after the update, for any function that you would normally use a variable for.
                      %NVAR is a counter that increases by 1 wiht each loop. This is used to walk through the %TVAR# variables. This could be done with %N, but that counts down, which I didn't like.
                      %TMP is the String Variable that contains the code that sets %VAR to a different %TVAR# variable with each loop.
                      %N is for the number of loops

                      {SET�%N,3}
                      {SET�%TVAR1,123}
                      {SET�%TVAR2,456}
                      {SET�%TVAR3,789}
                      {SET�%NVAR,1}
                      {:A}
                      {SET�%TMP,"{SET�%VAR,�%TVAR"+%NVAR+"}"}
                      {%TMP}
                      {SET�%NVAR,�VAL(%NVAR)+1}
                      {LOOP�:A,%N}

                      When you run this code in Debug mode you can see that %VAR will be "123" on loop 1, "456" on loop 2 and "789" at the end.

                      Thanks again Ira!

                      Comment

                      Working...
                      X