Cosmos75
Registered User.
- Local time
- Today, 05:13
- Joined
- Apr 22, 2002
- Messages
- 1,280
Try this for a cool way to have a messagebox greeting. Not my code, see bottom to find link where I found it.
Sub HowDidHeDoThat()
For x = 0 To 5
x1 = x1 & Chr(x * (x * (x * (x * (-0.75 * x + 7.2917) _
- 22.5) + 16.708) + 28.25) + 72)
Next x
For x = 0 To 6
x2 = x2 & Chr(x * (x * (x * (x * (x * (0.425 * x - 6.8667) _
+ 40.833) - 109.58) + 122.24) - 23.05) + 87)
Next x
MsgBox x1 & x2
End Sub
Don't read on if you don't want to know how this works.
Bob Umlas supplied the code, but the originator is unknown.
Still want to know how this works?
OK, I thought of writing my own explanations but someone has a better one. Here's how Damon Ostrander (You can find him posting on MrExcel.com) explained it. More elegantly than I could have done!
"Any text string can be represented by a sequence of numbers, one for each character, that represent the ASCII character codes of the characters. For example, the letter H is 72 in decimal, which is why the VBA function Chr(72) returns an "H". The two equations in this routine represent factored forms of two power series polynomials. For the case of the variable x1 in this code, these polynomials have been set up to represent a curve that passes exactly through the ASCII codes of all the characters in "Hello ". So this curve passes exactly through the points:
X Y
0 72 H
1 101 e
2 108 l
3 108 l
4 111 o
5 32 (space)
This represents a 5th-order polynomial, and requires solving for the 6 coefficients. The required order of the polynomial is always the number of points it must pass through minus 1. I wouldn't want to have to do this by hand, but this can be done by Excel using the curve-fitting capability. Breaking the string into two substrings enabled solving a 5th- and 6th-order polynomial rather than a single 12th-order polynomial, which is much harder.
Also, the curve doesn't have to EXACTLY pass through these points since they are integers. It must just exceed them by no more than one so that when they are truncated to the nearest integer they have the correct values."
Hope someone else finds this interesting!
Sub HowDidHeDoThat()
For x = 0 To 5
x1 = x1 & Chr(x * (x * (x * (x * (-0.75 * x + 7.2917) _
- 22.5) + 16.708) + 28.25) + 72)
Next x
For x = 0 To 6
x2 = x2 & Chr(x * (x * (x * (x * (x * (0.425 * x - 6.8667) _
+ 40.833) - 109.58) + 122.24) - 23.05) + 87)
Next x
MsgBox x1 & x2
End Sub
Don't read on if you don't want to know how this works.
Bob Umlas supplied the code, but the originator is unknown.
Still want to know how this works?
OK, I thought of writing my own explanations but someone has a better one. Here's how Damon Ostrander (You can find him posting on MrExcel.com) explained it. More elegantly than I could have done!
"Any text string can be represented by a sequence of numbers, one for each character, that represent the ASCII character codes of the characters. For example, the letter H is 72 in decimal, which is why the VBA function Chr(72) returns an "H". The two equations in this routine represent factored forms of two power series polynomials. For the case of the variable x1 in this code, these polynomials have been set up to represent a curve that passes exactly through the ASCII codes of all the characters in "Hello ". So this curve passes exactly through the points:
X Y
0 72 H
1 101 e
2 108 l
3 108 l
4 111 o
5 32 (space)
This represents a 5th-order polynomial, and requires solving for the 6 coefficients. The required order of the polynomial is always the number of points it must pass through minus 1. I wouldn't want to have to do this by hand, but this can be done by Excel using the curve-fitting capability. Breaking the string into two substrings enabled solving a 5th- and 6th-order polynomial rather than a single 12th-order polynomial, which is much harder.
Also, the curve doesn't have to EXACTLY pass through these points since they are integers. It must just exceed them by no more than one so that when they are truncated to the nearest integer they have the correct values."
Hope someone else finds this interesting!
Last edited: