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

Finding Highest value within multiple fields

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

    Finding Highest value within multiple fields

    Hi guys, I have 8 numeric fields on a form with different values. I need to select the field with the highest value, and use this value in a calculated field.
    Any idea's ?

    Thanks
    Fred

    #2
    Re: Finding Highest value within multiple fields

    Use max().

    Hint: You can "nest" max() expressions like you can if()

    highest = max(field1,max(field2,field3))
    There can be only one.

    Comment


      #3
      Re: Finding Highest value within multiple fields

      Thanks Stan, do I still have to create a massive expression to compare the 8 fields with all the various possibilities?
      Or does this max allow me to just specify the 8 fields in the expression and it somehow works out the highest value.
      Sorry to sound a bit thick, but I am not sure how this max function works.

      Fred

      Comment


        #4
        Re: Finding Highest value within multiple fields

        Fred,
        If you don't use the interactive editor, then definitely start!

        Here is an example doing just that. The question mark prior is used just for the interactive editor to show a result==the actual expression is after it.

        Code:
        dim fld1 as n=11
        dim fld2 as n=5
        dim fld3 as n=8
        dim fld4 as n=4
        dim fld5 as n=55
        dim fld6 as n=6
        dim fld7 as n=8
        dim fld8 as n=3
        
        ?max(fld8,max(fld7,max(fld6,max(fld5,max(fld4,max(fld3,max(fld1,fld2)))))))
        = 55
        I simply started with a single max() ---max(fld1,fld2), then used this result in a second max()---max(fld3,max(fld1,fld2)....and so on. You are just comparing the first result to the next.

        Take a look at the online help too --

        http://support.alphasoftware.com/alp...ions/MAX().htm
        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


          #5
          Re: Finding Highest value within multiple fields

          Hi Mike, I shall certainly take a look at the interactive editor window.
          I shall give this a go right now.
          Thanks for your help.

          Fred

          Comment


            #6
            Re: Finding Highest value within multiple fields

            The interactive editor is great for testing out expressions & code.
            Never used it before, but it really helped me sort out my problem.

            Thanks for suggesting it to me.

            Comment


              #7
              Re: Finding Highest value within multiple fields

              Hi again Mike, is it possible to use this max condition to rank all 8 fields from Highest to lowest? Iv'e had a go at this, but with no success as it looks very difficult.

              Fred

              Comment


                #8
                Re: Finding Highest value within multiple fields

                Fred,
                The attached contains a user defined function (UDF) named rank_list() that generates the a rank of the values in 8 fields on the form and displays it in a text box. I used the strategy of generating a list of the field values with attached field names, and then sorting the list based on the field value. See if this helps.
                Code:
                FUNCTION rank_list AS C ( )
                	
                dim vL as C=""
                dim t as P
                t = table.get("rank")
                
                dim vFN as N
                dim vFC as C
                for i = 1 to 8
                	vFN = eval("topparent:F"+i+".value")
                	vFC = alltrim(str(vFN))
                	vFC = padl(alltrim(vFC),4,"0")
                	vL = vL + vFC + " - " + "Field-" + i + crlf()
                next
                vL = sortsubstr(vL,crlf())
                
                dim vrank as C
                for each foo in vL
                	vrank = vrank + word(foo.value,2," - ",1) + " - " + stritran(word(foo.value,1," - ",1),"0","") + crlf()
                next
                
                parentform:text1.text = vrank
                	
                END FUNCTION
                Last edited by Mike Wilson; 02-15-2009, 06:19 PM.
                Mike W
                __________________________
                "I rebel in at least small things to express to the world that I have not completely surrendered"

                Comment


                  #9
                  Re: Finding Highest value within multiple fields

                  Thats great Mike. That sorts out the ranking order just fine.
                  My last task is to assign the values to fields which in turn will have a corresponding value.
                  ie..
                  Field 5 (Highest Rank) would = 2.16
                  Field 1 = 2.20
                  Field 2 = 2.24
                  Field 8 = 2.28
                  Field 3 = 2.32
                  Field 4 = 2.36
                  Field 6 = 2.40
                  Field 7 = 2.44

                  Any idea's Mike ?

                  Comment


                    #10
                    Re: Finding Highest value within multiple fields

                    Fred,
                    You lost me, I think. But to get ascending order with two decimal places as you have there, change line 11 of the UDF to be:

                    Code:
                    vFC = alltrim(str(vFN,10,2))
                    and line 19 to:
                    Code:
                    vrank = vrank + word(foo.value,2," - ",1) + " - " + padr(stritran(word(foo.value,1," - ",1),"0",""),4,"0") + crlf()
                    Mike W
                    __________________________
                    "I rebel in at least small things to express to the world that I have not completely surrendered"

                    Comment


                      #11
                      Re: Finding Highest value within multiple fields

                      Fred,
                      <soapbox on> Whenever you start putting multiple fields in the same record and those fields all have something in common, you should begin to rethink your design. Here your problem becomes trivial if you put the numeric fields in a separate table, one numeric field per record. You can then sort that table as needed. Stacking fields horizontally, by adding them to new "columns" for each record is what spreadsheets do well. Relational databases shine if you use them as databases, and not as spreadsheets. <soapbox off>.

                      Comment


                        #12
                        Re: Finding Highest value within multiple fields

                        I am not sure how this max function works.
                        Puzzling. Is the documentation not available to you or is there something in the documentation that isn't clear?

                        MAX()


                        Code:
                        Largest_Number as N = MAX( ListNumber as N, Number2 as N )
                        
                        Argument   Description
                         
                        ListNumber A number.
                         
                        Number2    A number.
                         
                        Description
                        
                        MAX() returns the larger of two numbers: ListNumber or Number2.
                        There can be only one.

                        Comment


                          #13
                          Re: Finding Highest value within multiple fields

                          Hi Stan, it's clear now...
                          Thanks again.

                          Comment


                            #14
                            Re: Finding Highest value within multiple fields

                            Hi Tom, the 8 fields I want to rank are actually the (tablesum) totals of 8 numeric fields, which are in just one table. I am trying to assign values to 8 other fields based on the ranking order of these 8 total fields.
                            Hope this makes sense.
                            Fred

                            Comment


                              #15
                              Re: Finding Highest value within multiple fields

                              Hi Mike, once I have ranked the 8 fields, which are actually tablesum totals, I then need to assign values to 8 other fields based on the ranking order.
                              Sorry for the confussion.
                              Fred

                              Comment

                              Working...
                              X