Normal Topic Dissecting a number (Read 944 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Dissecting a number
Dec 18th, 2007 at 7:30pm
Print Post Print Post  
I would like to design a form in which I can place a number in an element, and have programming break it apart digit by digit so that each digit goes into another separate element.  For example, if the number was 96,128,674, I want to place:
9 in element "Ten_Millions"
6 in element "Millions"
1 in element "Hundred_Thousands"
2 in element "Ten_Thousands"
8 in element "Thousands"
6 in element "Hundreds"
7 in element "Tens"
4 in element "Singles"

I have made the form and the target elements.  Can someone point me towards an sbasic command that will allow me to dissect the digits?  The number can range from 1 to 99,999,999.  No decimals are required.  Thanks in advance for any help.
  

**
Captain Infinity
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Dissecting a number
Reply #1 - Dec 18th, 2007 at 8:13pm
Print Post Print Post  
Use @Mid(NumberElement,n,1,NewElement)
Put NewElementNames in an array or delimited string, and separate them into Element"n" using the array position. 
Then loop through the digits.  By starting with the last digit, then you will end up with 0 or blank in shorter numbers.


Somethiing like this

n=0
DigitCount = @Len(NumberElement)
While (n<DigitCount) {
     @Mid(NumberElement,DigitCount - n,1,NewElement+@Str(DigitCount - n) )
     n = n + 1
     }




  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Dissecting a number
Reply #2 - Dec 18th, 2007 at 9:19pm
Print Post Print Post  
Bob_Hansen wrote on Dec 18th, 2007 at 8:13pm:
Use @Mid(NumberElement,n,1,NewElement)


@Mid() has three arguments. So syntax would be

Code
Select All
NewElement = @Mid(NumberElement,n,1) 



So the example would be

Code
Select All
Var n as Int
Var DigitCount as Int

n=0
DigitCount = @Len(NumberElement)
While (n < DigitCount)
{
	@("NewElement"+@Str(n+1)) = @Mid(NumberElement, DigitCount - n, 1)
	n = n + 1
}  



That assumes that the elements are named NewElement1, NewElement2, Etc.

NewElement1 gets the Singles
NewElement2 gets the Tens
And so on

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Dissecting a number
Reply #3 - Dec 18th, 2007 at 9:21pm
Print Post Print Post  
Scott, I tried to resist, but I just can't...

I must know: why do you need to do this?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Dissecting a number
Reply #4 - Dec 19th, 2007 at 1:23am
Print Post Print Post  
Thanks for fixing that sample Ray.  I should have noted it was a rough untested draft.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Dissecting a number
Reply #5 - Dec 19th, 2007 at 2:15pm
Print Post Print Post  
No problem Bob, That's what I am here for.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Dissecting a number
Reply #6 - Dec 19th, 2007 at 2:38pm
Print Post Print Post  
Quote:
Scott, I tried to resist, but I just can't...

I must know: why do you need to do this?


I don't actually need to do it, I'm considering it as a convenience for my Accounts Payable person.

Here's the situation:  whenever we institute a wire transfer through our bank, we are required to present to them a unique "key" number that is derived in a rather oblique way.  We have a "private number" that has been issued to our company, plus a sheet of codes.  Each month has a unique number code, as does each day of the month.  Then the amount we are transferring has a code which is determined as such:  the millions amount has a code, as does the hundred thousands, as does the ten thousands, and so on.  Once we determine all the individual codes we have to add them up, and the total is the "key code" for the transaction.  So, for example:

For a transfer made January 1 in the amount of $128,750.00:

Value             Code
Our number:   1234
January:           345
1st:                7668
100,000:          568
20,000:          3577
8,000:             980
700:              3664
50:                  296
0:                       0

Total (Key Code):  1234 + 345 + 7668 + 568 + 3577 + 980 + 3664 + 296 + 0 = 18332

I had no idea until yesterday she was going through this much BS, so I immediately created a Sesame form that would do the work for her, hard-coding all the key values in so all she has to do is pick a month, a day, a Millions value, a Hundred Thousands value, etc.  It's working well and will save a lot of time and hassle.  Then I thought, if the work required in coding wasn't too much trouble, an element where she could just put in the value to be transferred would be nice, and let Sesame break the sucker down.  I'm still undecided.  What I've got is working well and it only took about 15 minutes of work.

I may come back to the "dissect a number" idea if I've got some free time, but my boss plunked three new projects onto me this morning so it will have to wait.  Thanks to Bob and Ray for the advice.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Dissecting a number
Reply #7 - Dec 19th, 2007 at 2:44pm
Print Post Print Post  
Cool! Thanks for explaining.  Smiley
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Foster
Ex Member


Re: Dissecting a number
Reply #8 - Dec 19th, 2007 at 5:21pm
Print Post Print Post  
Wow!  I had no idea that sending money was that involved.  Very interesting.
  
Back to top
 
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Dissecting a number
Reply #9 - Dec 19th, 2007 at 9:18pm
Print Post Print Post  
It doesn't have to be that complex, but our bank wants to geometrically increase their chances of screwing it up.
  

**
Captain Infinity
Back to top
IP Logged