![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
|
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 (Original author unknown). http://www.j-walk.com/ss/excel/odd/odd17.htm |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
Hi Cosmos75,
Yes, this is a clever scheme for hiding the source of the message strings. If you are interested in how this is done, here is the explanation: 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. I feel like I've just "pulled the mask off the ol' Lone Ranger," but I don't intend to mess around with Jim.
__________________
Keep Excelling. Damon VBAexpert Excel Consulting (My other life: http://damonostrander.com ) |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Great explanation Damon.
I followed the j-walk link and see that Bob Umlas supplied the code, but the originator was unknown. I wonder who was so bored one day that they came up with that? I wouldn't be suprised if the technique harked back to the days of computers being for "geeks" only. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|