# Thread: quick help with a calculation

1. ## 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. ## 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. ## 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

4. ## 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?

5. ## 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. ## 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. ## Re: quick help with a calculation

Originally Posted by hov333
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) ?

8. ## Re: quick help with a calculation

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

9. ## 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. ## Re: quick help with a calculation

Originally Posted by hov333
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. ## 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. ## Re: quick help with a calculation

Originally Posted by hov333
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.

13. ## 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. ## Re: quick help with a calculation

Originally Posted by hov333
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.

15. ## Re: quick help with a calculation

Originally Posted by Tbaker
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. ## Re: quick help with a calculation

Originally Posted by hov333
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,"")

17. ## Re: quick help with a calculation

Originally Posted by Al Buchholz
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

18. ## 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. ## 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. ## Re: quick help with a calculation

Originally Posted by hov333
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. ## Re: quick help with a calculation

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

22. ## 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. ## 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. ## 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. ## Re: quick help with a calculation

Originally Posted by hov333
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...

26. ## Re: quick help with a calculation

Originally Posted by hov333
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?
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. ## 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. ## Re: quick help with a calculation

Originally Posted by G Gabriel
..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. ## Re: quick help with a calculation

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

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. ## 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.

#### Posting Permissions

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