Alpha Video Training
Page 1 of 2 12 LastLast
Results 1 to 30 of 52

Thread: quick help with a calculation

  1. #1
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default quick help with a calculation

    happy friday guys!

    quick question:

    I have 2 variables and 1 calculated field.

    var1 -> ignore = ""
    var2 -> scan_serial = ""

    calc-> (Var->IGNORE)-(var->scan_serial)

    I know this is incorrect but I'm hoping someone can help me with the proper way to define my calculated field.

    The "ignore" variable is supposed to subtract the characters from the "scan_serial" variable.

    i.e.

    ignore = C
    scan_serial = C1312
    my calculated field should read = 1312

    Thanks!

  2. #2
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: quick help with a calculation

    Wouldn't it be nice if it was that easy!
    Code:
    dim ignore as c= "C"
    dim scan_serial as c= "C1312"
    ?strtran(scan_serial,ignore,"")
    = "1312"

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: quick help with a calculation

    This should work

    Code:
     
    calcfield=strtran(scan_serial,ignore,"")

    here is code in interactive window

    ignore="C"
    scan_serial="C1322"
    calcfield=strtran(scan_serial,ignore,"")
    ?calcfield
    = "1322"

    Tom
    Last edited by Tbaker; 08-19-2011 at 03:35 PM. Reason: Added help info

  4. #4
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,643

    Default Re: quick help with a calculation

    is there a chance that the ignore string is more than 1 character and you want to ignore each of them no matter where they are?

    and/or are there other complications beyond the example given?
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  5. #5
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    no its pretty simple. I'm actually trying to set up an ignore string for before AND after. I'm going to try and use strtran(scan_serial,ignore,"") i'll see where this takes me

  6. #6
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    doesnt work. i'm getting a error " field 'ignore' not found". I don't think this works with variables. Is there another code where I can have ignore1 (before string) & ignore2 (after string) ?

  7. #7
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,643

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    doesnt work. i'm getting a error " field 'ignore' not found". I don't think this works with variables. Is there another code where I can have ignore1 (before string) & ignore2 (after string) ?
    please post your code..
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  8. #8
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    its exactly the code that Tom suggested:
    my calculated field is set to = strtran(scan_serial,ignore,"")

  9. #9
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    here is what I want to do, these are character based not numeric btw :

    my calc-> (Var->IGNORE1)-(var->scan_serial)-(Var->IGNORE2)

    So say:
    ignore1= S
    ignore2= D

    When a number is entered -> SXXD

    The result is XX

    The IGNORES will be removing the noted characters from the entered string

  10. #10
    "Certified" Alphaholic Ray in Capetown's Avatar
    Real Name
    Ray Hendler
    Join Date
    Jan 2009
    Location
    South Africa
    Posts
    2,036

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    its exactly the code that Tom suggested:
    my calculated field is set to = strtran(scan_serial,ignore,"")
    If that works for the first char then you can ignore any trailing characters (non numeric) with val()
    ?b
    = "8970k"

    ?val(b)
    = 8970

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: quick help with a calculation

    tst = "SXXD"

    ? stritran_multi(tst,"D"+crlf()+"S","")
    = "XX"

    ignore1 = "D"
    ignore2 = "S"
    ignore_list = ignore1+crlf()+ignore2

    ? stritran_multi(tst,ignore_list,"")
    = "XX"

  12. #12
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,643

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    here is what I want to do, these are character based not numeric btw :

    my calc-> (Var->IGNORE1)-(var->scan_serial)-(Var->IGNORE2)

    So say:
    ignore1= S
    ignore2= D

    When a number is entered -> SXXD

    The result is XX

    The IGNORES will be removing the noted characters from the entered string
    Actually that's not the code that Tom suggested.

    Your code is concatenating strings together. http://www.alphafivewiki.com/Charact...tion+Functions

    You can see all of the character functions here. http://www.alphafivewiki.com/Character+Functions


    remember when I asked this question?
    is there a chance that the ignore string is more than 1 character and you want to ignore each of them no matter where they are?

    It appears that is the case.

    It appears that you want build a calculated field, so do this. use strtran twice in the same expression - once on the original string and the second on the result.

    calcfield = strtran(strtran(scan_serial,ignore1,""),ignore2,"")


    Another option is what Stan did, which is more suited for a script or function.

    Ray's solution is another way to approach stripping any character from the 'numeric' part of a string.
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  13. #13
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    thanks for the reply stan, but this may as well be Swahili for me.

    I tried your code but heres the issue:
    Lets say
    tst = "DSXXD"

    ? stritran_multi(tst,"D"+crlf()+"S","")
    = "XX"

    I only want ignore1 to remove the string BEFORE and string2 to remove the string AFTER the entered value. Your code is remove the character that is anywhere in the string.

    Heres another example:

    ignore1= S
    ignore2= D

    When a number is entered -> SXXDSSD

    The result has to be = XXDSS (not XX)

  14. #14
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,643

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    I only want ignore1 to remove the string BEFORE and string2 to remove the string AFTER the entered value. Your code is remove the character that is anywhere in the string.

    Heres another example:

    ignore1= S
    ignore2= D

    When a number is entered -> SXXDSSD

    The result has to be = XXDSS (not XX)
    context is very important.

    I'd suggest that you post an example form/browse of what you really want to do.
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  15. #15
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    Quote Originally Posted by Tbaker View Post
    This should work

    Code:
     
    calcfield=strtran(scan_serial,ignore,"")

    Tom
    thats what I got from Tom, thanks for your help though. I will try these other options and see what happens.

  16. #16
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,643

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    thats what I got from Tom, thanks for your help though. I will try these other options and see what happens.
    There is a considerable difference between

    my calc-> (Var->IGNORE1)-(var->scan_serial)-(Var->IGNORE2)

    and

    calcfield=strtran(scan_serial,ignore,"")
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  17. #17
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    Quote Originally Posted by Al Buchholz View Post
    context is very important.

    I'd suggest that you post an example form/browse of what you really want to do.
    I have a total of 3 variables and 1 calculated result:
    scan_serial
    ignore1
    ignore2

    ignore1-scan_serial-ignore2=result

    I don't know how else I can provide an example. The order is important thats why I have put ignore2 to remove the trailing string from scan_serial
    Last edited by Al Buchholz; 08-23-2011 at 01:35 PM. Reason: highlight what is needed....

  18. #18
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    my calc-> (Var->IGNORE1)-(var->scan_serial)-(Var->IGNORE2)

    I'm sorry for the confusion, by this I was trying to show (logically) how I want the function to work.
    by no means is this what I'm entering as the calculation

  19. #19
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: quick help with a calculation

    Code:
    scan_serial = "SXXD"
    ignore1 = "S"
    ignore2 = "D"
    
    out = if(left(scan_serial,1) = ignore1,"",left(scan_serial,1)) + substr(scan_serial,2,len(scan_serial)-2)+if(right(scan_serial,1) = ignore2,"",right(scan_serial,1))
    ? out
    = "XX"
    
    scan_serial = "SSSXXDSD"
    out = if(left(scan_serial,1) = ignore1,"",left(scan_serial,1)) + substr(scan_serial,2,len(scan_serial)-2)+if(right(scan_serial,1) = ignore2,"",right(scan_serial,1))
    ? out
    = "SSXXDS"

  20. #20
    "Certified" Alphaholic Ray in Capetown's Avatar
    Real Name
    Ray Hendler
    Join Date
    Jan 2009
    Location
    South Africa
    Posts
    2,036

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    thanks for the reply stan, but this may as well be Swahili for me.......When a number is entered -> SXXDSSD
    The result has to be = XXDSS (not XX)
    Now you're speaking clear Swahili - got it - what you want is maybe
    Code:
    b="D87C88D"
    ?substr(b,2,5)
    = "87C88"
    Maybe if you want the first and last chr removed then include len()
    subs(b,2,len(b)-2) and if thats not it - give us another clue.
    Ha

  21. #21
    "Certified" Alphaholic
    Real Name
    Tom Baker
    Join Date
    Jun 2006
    Location
    Near Cherry Hill, NJ
    Posts
    1,296

    Default Re: quick help with a calculation

    How about something like this

    Code:
    DIM IGNORE1 AS C
    DIM IGNORE2 AS C
    DIM SCAN_SERIAL AS C
    DIM CALC_FIELD AS C
    
    IGNORE1="S"
    IGNORE2="D"
    SCAN_SERIAL="SXXDSSD"
    
    CALC_FIELD=strtran(SCAN_SERIAL,ignore1,"",1,1)
    
    msgbox("SXXDSSD",CALC_FIELD)
    
    CALC_FIELD=strtran(*reverse(CALC_FIELD),ignore2,"",1,1)
    
    CALC_FIELD=*REVERSE(CALC_FIELD)
    msgbox("SXXDSSD", CALC_FIELD)

    Tom
    Last edited by Tbaker; 08-23-2011 at 02:13 PM. Reason: changed code

  22. #22
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: quick help with a calculation

    Not that it matters in any way other than that it's a waste of cyber space but evidently you did not read my first post..
    Translating your question from Swahilli to English:
    I want ignore1 to remove the first occurrance of ignore1
    And I want ignore2 to remove the last occurrance of ignore2
    Assuming my Swahilli is still fresh, here is one way:
    Code:
    dim userNo as c="SXXDSSD"
    dim ignore1 as c= "S"
    dim ignore2 as c= "D"
    
    ?stuff(stuff(userNo,1,1,""),at(ignore2,userNo,occurs(ignore2,userNo)),1,"")
    = "XXDSSD"
    Of course, there are many other ways to do this..just want to make sure my Swahilli interpretation is good before getting too deep in the weeds.

  23. #23
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    haha thanks for all the input guys. By swahilli I meant trying to make sense of all this coding.

    I don't need the full code that everyone is providing, I already have my dialog boxes set up and variables set up via the codeless action scripts. I just need help with the calculated field.

    First off, I don't want to be just removing the first or last characters, but instead the EXACT string that is the ignore1 & ignore2 fields. Lol this is getting ridiculously complicated, either my examples are horrible or theres a good reason why programmers get paid good $.

    At least logically this seemed like a pretty simple task...

    Looks like there are a lot of ways to achieve the same result. I wish I knew an easy way to just upload only the form, anyway here is the code I'm using that works perfectly except that it removes the characters without attention to order.

    scan_seriall = stritran_multi(Var->scan_serial,Var->ignore1+crlf()+Var->ignore2,"")

    Sorry Gabriel I didn't ignore your post, I just didn't know what to think of it since it was all code...I actually still don't know what context to even use that in.

  24. #24
    Member
    Real Name
    Tony Evans
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    46

    Default Re: quick help with a calculation

    DIM IGNORE1 AS C = "S"
    DIM IGNORE2 AS C = "D"
    DIM SCAN_SERIAL AS C = "SXXDSSD"

    DIM CALC_FIELD AS C = chrtran(left(scan_serial, 1), ignore1, "") + mid(scan_serial, 2, len(scan_serial) - 2) + chrtran(right(scan_serial, 1), ignore2, "")
    ?calc_field
    = "XXDSS"

    Note: this only works for single character ignore? values, and only works for single occurences of the ignore? values.

  25. #25
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,643

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    First off, I don't want to be just removing the first or last characters, but instead the EXACT string that is the ignore1 & ignore2 fields. Lol this is getting ridiculously complicated, either my examples are horrible or there's a good reason why programmers get paid good $. (yup)

    At least logically this seemed like a pretty simple task...
    Application development is a details oriented world. Not much room for assumptions.

    To upload a form, you'll need to send a table/set(and it's tables) so we can see directly what you are doing.

    Short of that we are shooting in the dark...
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

  26. #26
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: quick help with a calculation

    Quote Originally Posted by hov333 View Post
    First off, I don't want to be just removing the first or last characters, but instead the EXACT string that is the ignore1 & ignore2 fields.
    Now you went way deep in the forest where they speak a completely different dialect of Swahilli.
    What exactly do you mean?
    In your example:
    Code:
    ignore1= S
    ignore2= D
    
    When a number is entered -> SXXDSSD
    
    The result has to be = XXDSS (not XX)
    Clearly there is more than one S & more than one D. Which S and which D do you want to remove?

  27. #27
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    tony, would I be able to copy paste this somewhere?

    Right now I'm working between the Form->"variables" & Form->"calculated fields" drop-downs from my form window.

  28. #28
    "Certified" Alphaholic Ray in Capetown's Avatar
    Real Name
    Ray Hendler
    Join Date
    Jan 2009
    Location
    South Africa
    Posts
    2,036

    Default Re: quick help with a calculation

    Quote Originally Posted by G Gabriel View Post
    ..just want to make sure my Swahilli interpretation is good before getting too deep in the weeds.
    two comments, I still have a bit of cyberspace;-
    1. Gabe - you know, they actually speak Swahili about 3hrs flight north of here, and I could stop off in Malawi on the way, they have great weeds
    2. HOV333 "this seemed like a pretty simple task.." when someone tells me their requirement is simple I feel the same as when someone starts their sentence with "trust me.."

  29. #29
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    329

    Default Re: quick help with a calculation

    so ignore1 is looking before scan_serial and ignore2 is after scan_serial.

    That's why I had written:
    my calc-> (Var->IGNORE1)-(var->scan_serial)-(Var->IGNORE2)

    to show as an example, not an actual function but it probably caused more confusion than it was worth.

    lol Ray i guess you're right. I've learned that almost nothing is as simple as it seems in my experiences with A5. I've gotten spoiled by being in the Google generation i guess :(

  30. #30
    Member
    Real Name
    Tony Evans
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    46

    Default Re: quick help with a calculation

    If you provide a input/result table that shows what result you want for various input values, it would be easier to understand what you are looking for.

    e.g. the 12:41 post will provide these results:
    SXXDSSD -> XXDSS
    SSXXDSSDD -> SXXDSSD
    SXXDSS -> XXDSS
    XXDSSD -> XXDSS
    etc.

Similar Threads

  1. Just a quick ?
    By vpmedia in forum Alpha Five Version 9 - Desktop Applications
    Replies: 17
    Last Post: 11-28-2009, 07:50 AM
  2. Just a quick ?
    By vpmedia in forum Alpha Five Version 9 - Desktop Applications
    Replies: 11
    Last Post: 10-09-2009, 03:48 PM
  3. Some quick help
    By robdims in forum Application Server Version 8
    Replies: 4
    Last Post: 09-24-2007, 05:54 AM
  4. Uh Oh! Need some quick help!
    By pps in forum Alpha Five Version 5
    Replies: 2
    Last Post: 06-08-2004, 02:47 PM
  5. Quick - Quick Filter Question
    By forskare in forum Alpha Five Version 4
    Replies: 2
    Last Post: 05-08-2001, 10:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •