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

Compare Numeric Variables

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

    Compare Numeric Variables

    I have 6 variables each with a number in them round(Rand()*53,0)
    I want to then copy each number from the variables to feilds on a form but in numberic order. Is there any way to sort the varibles so I can then copy the numbers in order?

    What Im doing now is to enter each number into a one colume temp table, then i sort the colum then copy the 1st record to the main table, then go to next record in the temp table then copy that record to the main table and so forth.

    #2
    Re: Compare Numeric Variables

    store the numbers in an array, then sort the array.

    http://support.alphasoftware.com/alp...SORT%28%29.htm
    Andrew

    Comment


      #3
      Re: Compare Numeric Variables

      And you could do something like this.....

      Code:
      for i = 1 to 6
      eval("var"+alltrim(str(i))) = alltrim(str(round(Rand()*53,0)))
      next i
      
      ? var1
      = "48"
      ? var2
      = "33"
      ? var3
      = "45"
      ? var4
      = "41"
      ? var5
      = "29"
      ? var6
      = "10"
      
      whole = var1+","+var2+","+var3+","+var4+","+var5+","+var6
      ? whole
      = "48,33,45,41,29,10"
      
      sorted = sortsubstr(whole,",","A","N")
      ? sorted
      = "10,29,33,41,45,48"
      
      for i = 1 to 6
      #? val(word(sorted,i,","))
      #next i
      10.000000
      29.000000
      33.000000
      41.000000
      45.000000
      48.000000
      There can be only one.

      Comment


        #4
        Re: Compare Numeric Variables

        I couldnt understand the array examples.
        I like your example Stan, but it seems at the end whaen the values are sorted they are no longer in the variables. I would need the variables to contain thier values even after they are sorted.

        Comment


          #5
          Re: Compare Numeric Variables

          Just reassign them.

          Code:
          for i = 1 to 6
          eval("var"+alltrim(str(i))) = alltrim(str(round(Rand()*53,0)))
          next i
          
          
          ? var1
          = "4"
          
          ? var2
          = "5"
          
          ? var3
          = "33"
          
          ? var4
          = "4"
          
          ? var5
          = "41"
          
          ? var6
          = "47"
          
          whole = var1+","+var2+","+var3+","+var4+","+var5+","+var6
          ? whole
          = "4,5,33,4,41,47"
          
          sorted = sortsubstr(whole,",","A","N")
          ? sorted
          = "4,4,5,33,41,47"
          
          for i = 1 to 6
          eval("var"+alltrim(str(i))) = val(word(sorted,i,","))
          next i
          
          ? var1
          = "4"
          
          ? var2
          = "4"
          
          ? var3
          = "5"
          
          ? var4
          = "33"
          
          ? var5
          = "41"
          
          ? var6
          = "47"
          Looks like, since the variables were originally assigned as character, the reassignment leaves them as character. You can just use the value of the variable to put in the field.
          Last edited by Stan Mathews; 01-14-2011, 04:37 PM.
          There can be only one.

          Comment


            #6
            Re: Compare Numeric Variables

            Hey Stan, Im loving what I'm seeing, will take me a while longer to truely understand it all, but it's nice. One more thing, in your second example you have "4" twice. It took me a lot of action scripting to try to prevent duplicate numbers and it still didnt work correct. can you incorporate something like that in your codes? I want 6 unique numbers.

            Comment


              #7
              Re: Compare Numeric Variables

              Aaron provided this a few years back.

              FUNCTION RandIntBetween AS N ( start AS N, end AS N )
              RandIntBetween = ceiling(rand() * (end-start-1) + start)
              END FUNCTION

              So if you save that function and substitute it...

              Code:
              for i = 1 to 6
              eval("var"+alltrim(str(i))) = alltrim(str(Randintbetween(1,99)))
              next i
              ? var1
              = "76"
              ? var2
              = "42"
              ? var3
              = "98"
              ? var4
              = "63"
              ? var5
              = "39"
              ? var6
              = "30"
              
              whole = var1+","+var2+","+var3+","+var4+","+var5+","+var6
              ? whole
              = "76,42,98,63,39,30"
              sorted = sortsubstr(whole,",","A","N")
              ? sorted
              = "30,39,42,63,76,98"
              for i = 1 to 6
              eval("var"+alltrim(str(i))) = val(word(sorted,i,","))
              next i
              ? var1
              = "30"
              
              ? var2
              = "39"
              
              ? var3
              = "42"
              
              ? var4
              = "63"
              
              ? var5
              = "76"
              
              ? var6
              = "98"
              There can be only one.

              Comment


                #8
                Re: Compare Numeric Variables

                Hey Stan,
                I know you would expect me to have this figured out by now, but I still don't, I took the parts from your example that I understand and added my own to it, as you can see below.

                'Insert label into script: 'Loop'.
                LOOP:

                'I dim all 6 variables individually
                dim Global RandomNumber1 as N
                dim Global RandomNumber2 as N
                dim Global RandomNumber3 as N
                dim Global RandomNumber4 as N
                dim Global RandomNumber5 as N
                dim Global RandomNumber6 as N

                'Then I filled each with a random number between 1 and 53
                RandomNumber1 = round(Rand()*53,0)
                RandomNumber2 = round(Rand()*53,0)
                RandomNumber3 = round(Rand()*53,0)
                RandomNumber4 = round(Rand()*53,0)
                RandomNumber5 = round(Rand()*53,0)
                RandomNumber6 = round(Rand()*53,0)

                'I know your code explains how to ensure 6 unique numbers pretty easier than this but i didn't understand how it works nor did it when I copy and paste it.
                This set of codes checks each of the 6 numbers againt the other five, if any 2 are the same it goes back to the top and start over.
                IF a5_eval_expression("=Var->RandomNumber1 = Var->RandomNumber2 .OR."+chr(13)+chr(10)+"Var->RandomNumber1 = Var->RandomNumber3 .OR."+chr(13)+chr(10)+"Var->RandomNumber1 = Var->RandomNumber4 .OR."+chr(13)+chr(10)+"Var->RandomNumber1 = Var->RandomNumber5 .OR."+chr(13)+chr(10)+"Var->RandomNumber1 = Var->RandomNumber6"+chr(13)+chr(10)+".OR."+chr(13)+chr(10)+"Var->RandomNumber2 = Var->RandomNumber3 .OR."+chr(13)+chr(10)+"Var->RandomNumber2 = Var->RandomNumber4 .OR."+chr(13)+chr(10)+"Var->RandomNumber2 = Var->RandomNumber5 .OR."+chr(13)+chr(10)+"Var->RandomNumber2 = Var->RandomNumber6"+chr(13)+chr(10)+".OR."+chr(13)+chr(10)+"Var->RandomNumber3 = Var->RandomNumber4 .OR."+chr(13)+chr(10)+"Var->RandomNumber3 = Var->RandomNumber5 .OR."+chr(13)+chr(10)+"Var->RandomNumber3 = Var->RandomNumber6"+chr(13)+chr(10)+".OR."+chr(13)+chr(10)+"Var->RandomNumber4 = Var->RandomNumber5 .OR."+chr(13)+chr(10)+"Var->RandomNumber4 = Var->RandomNumber6"+chr(13)+chr(10)+".OR."+chr(13)+chr(10)+"Var->RandomNumber5 = Var->RandomNumber6") THEN
                'Redo if all is not unique
                GOTO LOOP

                END IF


                'Create a string of all 6 numbers, this part I understood and got to work.
                dim Global whole as C
                whole = RandomNumber1+","+RandomNumber2+","+RandomNumber3+","+RandomNumber4+","+RandomNumber5+","+RandomNumber6

                'Sort the string with the 6 numbers. I got this too
                dim Global wholesorted as C
                wholesorted = sortsubstr(whole, ",", "A", "N")

                'Trying to get the sorted numbers back into the variables, Totally lost here mein.
                'eval("var"+alltrim(str(i))) = val(word(sorted,i,","))
                'next i

                I cant get any of the eval() line to function
                I would like you to use my codes then please edit the end to place back the 6 numbers in the 6 variables but this time sorted.
                I await your assistance, much appreciation as always.

                Comment


                  #9
                  Re: Compare Numeric Variables

                  Since you changed the names of the variables you need

                  Code:
                  for i = 1 to 6
                  eval("RandomNumber"+alltrim(str(i))) = val(word(wholesorted,i,","))
                  next i
                  There can be only one.

                  Comment


                    #10
                    Re: Compare Numeric Variables

                    It makes no sense to me. How can such little coding do so much? It works perfectly Stan, thanks a million mein.

                    Comment


                      #11
                      Re: Compare Numeric Variables

                      I believe eval() us the only function that can be used on the left side of an equals sign. This usage is somewhat nonintuitive but very powerful, as you note.

                      Here are some examples from playing in the interactive.
                      Code:
                      nigeldude = "pretty cool guy"
                      ? eval("nigel"+"dude")
                      = "pretty cool guy"
                      ? nigeldude
                      = "pretty cool guy"
                      
                      eval("nigel"+"dude") = "sometimes sleepy"
                      ? eval("nigel"+"dude")
                      = "sometimes sleepy"
                      
                      ? eval("n"+"i"+"g"+"e"+"l"+"d"+"u"+"d"+"e")
                      = "sometimes sleepy"
                      
                      
                      nigeldude1 = "the original"
                      nigeldude2 = "an imposter"
                      nigeldude3 = "a clone of nigeldude"
                      
                      i = 3
                      ? nigeldude +alltrim(str(i))
                      = "sometimes sleepy3"
                      
                      ? eval(nigeldude +alltrim(str(i)))
                      ERROR: Variable "sometimes sleepy3" not found.
                      ? eval("nigeldude" +alltrim(str(i)))
                      = "a clone of nigeldude"
                      So this line

                      eval("RandomNumber"+alltrim(str(i))) = val(word(wholesorted,i,","))

                      executes as

                      evaluate the expression "RandomNumber"+alltrim(str(i)))
                      and assign to it (=)
                      the value returned by val(wholesorted,i,","))

                      Put that line in a for loop (i as the iterator) and voila!
                      Last edited by Stan Mathews; 03-30-2011, 08:45 AM.
                      There can be only one.

                      Comment


                        #12
                        Re: Compare Numeric Variables

                        Originally posted by nigeldude View Post
                        I couldnt understand the array examples.
                        Code:
                        dim arr[6] as N
                        
                        arr[1] = 31
                        arr[2] = 17
                        arr[3] = 9
                        arr[4] = 42
                        arr[5] = 21
                        arr[6] = 33
                        
                        arr.sort()
                        
                        ?arr
                        = [1] = 9.000000
                        [2] = 17.000000
                        [3] = 21.000000
                        [4] = 31.000000
                        [5] = 33.000000
                        [6] = 42.000000
                        As was mentioned before, if you simply assign the variables to an array, the sort() method applied to the array name will do all of the sorting for you.

                        Steve

                        Comment


                          #13
                          Re: Compare Numeric Variables

                          Code:
                          FUNCTION Rand_6 AS N ( )
                          dim cnt as n=1
                          dim vnum as n
                          while cnt<7
                            vnum=(cnt-1)*9+round(rand()*8,0)
                            evaluate_template("dim global RandomNumber"+cnt+" as n="+vnum)
                            cnt=cnt+1
                          end while
                          END FUNCTION
                          Code:
                          Rand_6()
                          ?RandomNumber1
                          = 7
                          ?RandomNumber2
                          = 14
                          ?RandomNumber3
                          = 26
                          ?RandomNumber4
                          = 32
                          ?RandomNumber5
                          = 41
                          ?RandomNumber6
                          = 52
                          Run the function again.. you will get different numbers, all sorted ascending..

                          Comment


                            #14
                            Re: Compare Numeric Variables

                            You guys are doing a terrific job, I'll study these and play around with them in A5 so I can hopefully understand them.

                            I have a another question: now that I can successfully generate my sequences of 6 unique numbers, properly sorted and entered into a table with the columns "RandomNumber1" through to "RandomNumber6".
                            Lets say I generate one hundred different sequences, which is 100 rows or 100 lines. Keep in mind this is also 600 different numbers ranging from 1 - 53, if i want to do a count to show for example, how many times each number was generated, whats the best way to go about this? It could be to show all 53 numbers, or maybe just the top 10 or the bottom 10

                            I tried it the long way, doing a query for each number one at a time, and I didn't like the results, any pointers?

                            Comment


                              #15
                              Re: Compare Numeric Variables

                              If you put them in a table, then use any one of the counting functions:
                              tablecount()
                              dbcount()
                              ..etc

                              Comment

                              Working...
                              X