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

How to Manipulate Strings to be used for computation

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

    How to Manipulate Strings to be used for computation

    This is the computation that I would like to do on a computation to be saved on a field

    Given
    Price = 200
    Discount = ?
    There are 3 discount variations that I want to compute depending on the input of the user.
    1.First variation of the Discount is when the user enters +6 as the discount
    if the user entered +6 then the formula is = 200 + (200* (6/100))
    to simplify that = 200 + (200*.06)
    Result = 200 +12
    Result = 212 Final Price

    2. Second Variation of the Formula is when a user enter -6 or -7 or -9 etc. lets take - 6 again as our example
    to simplify that = 200 + (200*-.06)
    Result = 200 -12
    Result = 188 Final Price
    The first two variations are easy to without the third variation

    3. The last variation is when the user enters 10+2, or 12+3, or 6+4 etc. lets take for example 10+2
    to simplify that = (200 * 10) / (10+2)
    (200*10)/12
    Result = 166.67

    another example of the 3rd variation is , lets say a user enters 12+3

    (200 * 12) / (12+3)
    (200*12) /15
    Result = 160

    How can I possibly compute for this is , my problem here is to determine for the user input of the discount if it is variation 1 or variation 2 or variation 3. Can how do I do this?

    #2
    Re: HOw to Manipulate Strings to be used for computation

    Try this.
    If you are allowing the discount to be entered in a freeform text field then there is a lot of scope for errors. The code below attempts to catch some of these errors but is not complete. More could be done at the UI level.


    Code:
    dim price_lnv as N
    dim disc_lcv as C
    dim result_lnv as N
    dim pluspos_lnv as N
    dim minuspos_lnv as N
    
    
    price_lnv = 200 'ui_get_number("Price","Enter a price:") '\\enter starting price.
    
    disc_lcv = ui_get_text("Discount","Enter a discount:")  '\\enter the discount
    pluspos_lnv = at("+",disc_lcv)                          '\\determine the position, if any, of
    minuspos_lnv = at("-",disc_lcv)                         '\\ the + or - symbol (sign)
    
    
    '\\check for improper discount string
    '\\   --- missing symbol   -------- minus used in variation 3  -----   both symbols used  -----------
    If (pluspos_lnv + minuspos_lnv < 1) .or. minuspos_lnv > 1 .or. (pluspos_lnv > 0 .and. minuspos_lnv > 0) then
    	msgbox("Incorrect discount specified" +crlf(2) + "\""+disc_lcv + "\"")
    	end
    end if
    '\\there are still more possible errors in the discount input string. Either add more tests here or change the 
    '\\user interface to eliminate some of the possible errors. ie "10 2+" 
    select
    	case pluspos_lnv = 1  '\\variation 1
    	  result_lnv = price_lnv + (price_lnv * val(word(disc_lcv,2,"+"))/100)
    	case minuspos_lnv = 1 '\\variation 2
    	  result_lnv = price_lnv - (price_lnv * val(word(disc_lcv,2,"-"))/100)
    	case pluspos_lnv > 1  '\\variation 3
    	  result_lnv = (price_lnv * val(word(disc_lcv,1,"+"))) / eval(disc_lcv)
    end select
    
    result_lnv = round(result_lnv,2)
    msgbox("",""+result_lnv)
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

    Comment


      #3
      Re: HOw to Manipulate Strings to be used for computation

      Thank you so much Tim, the key command that you showed me that solves what I want to achieve are these two commands at("+",disc_lcv) and at("-",disc_lcv). My problem now is, how to get the value of 200 which is the user given price and the discount when I am on a dialog component or a grid component by not using the prompt ui commands. eg. In visual basic .net or C# for example, when I want to get or set the value of a textbox called txtPrice and txtDiscount then I would write txtPrice.Text and txtDiscount.Text. How do I do this on text on a dialog component? and how do I get the text value when I am on a grid component on any column depending on the location or column of the price?
      Last edited by doorscomputers; 06-30-2013, 09:17 AM.

      Comment


        #4
        Re: HOw to Manipulate Strings to be used for computation

        Originally posted by doorscomputers View Post
        How do I do this on text on a dialog component? and how do I get the text value when I am on a grid component on any column depending on the location or column of the price?
        Uhmmm, i think this is a question for a web forum.
        Tim Kiebert
        Eagle Creek Citrus
        A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

        Comment


          #5
          Re: HOw to Manipulate Strings to be used for computation

          Originally posted by Tim Kiebert View Post
          Uhmmm, i think this is a question for a web forum.
          Can be on the desktop right? web components for the desktop or WCD as they term it here. not sure but I have some grid and dialog components on my desktop app.

          Comment


            #6
            Re: How to Manipulate Strings to be used for computation

            I want to apply the Code that Tim posted and I think it is the right way to do it, I want to do it in a dialog component but I dont know how to reference the input fields in code when I am in a dialog component, also I tried to find the OnDepart event on the discount field so that after specifying the discount , when a user leaves the field then it will automatically display the computed result in the result field. I have attached an image of a dialog component and some sample data entry fields. Please help!
            Attached Files

            Comment


              #7
              Re: How to Manipulate Strings to be used for computation

              Roman


              Originally posted by doorscomputers View Post
              1.First variation of the Discount is when the user enters +6 ....Result = 200 +12 = 212 Final Price
              2. Second Variation of the Formula is when a user enter -6 ....Result = 200 -12 = 188 Final Price
              3. The last variation is when the user enters 10+2 ...........(200*10)/12 = 166.67
              You really need to be consistent
              case1 plus 6 discount increases the price by the perc
              case 2 minus 6 reduces the price by the perc
              case 3 PLUS 10+2 REDUCES THE PRICE opposing case1

              Maybe different over here but in price negotiations at wholesale level common speak is, for example
              eg.1 "less 10" - is understood as 200.00 less 10% (20.00) = 80
              eg,2."less 10+5" is understood as 200.00 less 10% 20.00) = 80, less another 5% (16.00) = 64.00
              is that what you are attempting?
              Last edited by Ray in Capetown; 07-03-2013, 05:50 AM.

              Comment


                #8
                Re: How to Manipulate Strings to be used for computation

                Originally posted by Ray in Capetown View Post
                Roman


                You really need to be consistent
                case1 plus 6 discount increases the price by the perc
                case 2 minus 6 reduces the price by the perc
                case 3 PLUS 10+2 REDUCES THE PRICE opposing case1

                Maybe different over here but in price negotiations at wholesale level common speak is, for example
                eg.1 "less 10" - is understood as 200.00 less 10% (20.00) = 80
                eg,2."less 10+5" is understood as 200.00 less 10% 20.00) = 80, less another 5% (16.00) = 64.00
                is that what you are attempting?
                Thank you Ray for trying to help
                Case 1 and Case 2 are standard discount that can be found on books and we have learned it in school.Option 3 is a custom formula, so do not concentrate on the formulas. The solution of Tim is the one that I am looking for, he tried to get for the value given by the user, then he tries to get the value if it starts with (+) positive then he executes formula 1, if he gets )-) negative then he executes Formula 2, and if the input does not start with negative or positive then he executes formula 3. The formulas are not the focus here. The solution is already given by Tim, but instead of prompting the user to input values on message prompt, I want the user to input the values on input fields in a grid component or dialog component for the desktop. but I dont know how to get the value on fields in an input field on the grid. IN visual basic, if I want to get the value of txtdiscount I type this, txtdiscount.text and if I want to assign a value on it, i would say txtDiscount.text = Price * Discount . On the desktop, it is very easy using action script right, point and click to get or set the values of fields and get or set the value of variables etc. How do I do this on Web Components? Thanks very much!
                Last edited by doorscomputers; 07-03-2013, 02:14 PM.

                Comment


                  #9
                  Re: How to Manipulate Strings to be used for computation

                  Aha. Ok

                  Comment


                    #10
                    Re: How to Manipulate Strings to be used for computation

                    Here is the Solution in Javascript for newbies like me. The one given by Tim on Post #2 is the solution on the regular Alpha Five Form.
                    Put whatever function in the Grid component|Properties|Javascript Functions Declarations property . this video by Selwyn is useful for this here is the link http://www.ajaxvideotutorials.com/V1...lculations.swf. Thanks!

                    function CompueDisc(Price,Dscount,sgn) {
                    var strPlus=Dscount;
                    var strMinus=Dscount;
                    var nPlus=strPlus.indexOf("+");
                    var nMinus=strMinus.indexOf("-");
                    var str=Dscount;
                    var n=str.split("+",2);

                    var nnn=strPlus.substr(0,2)
                    var nnnn=strMinus.substr(2)

                    if (sgn == "+")
                    {
                    //Put whatever calculations here
                    return Price + Dscount
                    }
                    else if
                    (sgn == "-")
                    {
                    //Put whatever calculations here
                    return Price * Dscount
                    }
                    else if (sgn == "c")
                    {
                    if (nPlus ==2)
                    {
                    //Put whatever calculations here
                    return Price + Dscount
                    }
                    else if (nMinus ==2)
                    {
                    //Put whatever calculations here
                    return Price + Dscount
                    }
                    else
                    {
                    //Put whatever calculations here
                    return Price + Dscount

                    }
                    }
                    }

                    Comment

                    Working...
                    X